Merge pull request #22583 from azat/log-rwlock-ub-fix

Avoid UB in *Log engines for rwlock unlock due to unlock from another thread
This commit is contained in:
alexey-milovidov 2021-04-05 05:20:16 +03:00 committed by GitHub
commit 6cefb8e620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 30 additions and 2 deletions

View File

@ -357,6 +357,11 @@ void LogBlockOutputStream::writeSuffix()
streams.clear();
done = true;
/// unlock should be done from the same thread as lock, and dtor may be
/// called from different thread, so it should be done here (at least in
/// case of no exceptions occurred)
lock.unlock();
}

View File

@ -86,7 +86,7 @@ private:
DiskPtr disk;
String table_path;
mutable std::shared_timed_mutex rwlock;
std::shared_timed_mutex rwlock;
Files files;

View File

@ -228,6 +228,11 @@ public:
storage.file_checker.save();
done = true;
/// unlock should be done from the same thread as lock, and dtor may be
/// called from different thread, so it should be done here (at least in
/// case of no exceptions occurred)
lock.unlock();
}
private:

View File

@ -68,7 +68,7 @@ private:
size_t max_compress_block_size;
FileChecker file_checker;
mutable std::shared_timed_mutex rwlock;
std::shared_timed_mutex rwlock;
Poco::Logger * log;
};

View File

@ -358,6 +358,9 @@ void TinyLogBlockOutputStream::writeSuffix()
storage.file_checker.update(file);
storage.file_checker.save();
/// unlock should be done from the same thread as lock, and dtor may be
/// called from different thread, so it should be done here (at least in
/// case of no exceptions occurred)
lock.unlock();
}

View File

@ -0,0 +1,5 @@
DROP TABLE IF EXISTS underlying_01795;
CREATE TABLE underlying_01795 (key UInt64) Engine=TinyLog();
INSERT INTO FUNCTION remote('127.1', currentDatabase(), underlying_01795) SELECT toUInt64(number) FROM system.numbers LIMIT 1;
SELECT * FROM underlying_01795 FORMAT Null;
DROP TABLE underlying_01795;

View File

@ -0,0 +1,5 @@
DROP TABLE IF EXISTS underlying_01796;
CREATE TABLE underlying_01796 (key UInt64) Engine=Log();
INSERT INTO FUNCTION remote('127.1', currentDatabase(), underlying_01796) SELECT toUInt64(number) FROM system.numbers LIMIT 1;
SELECT * FROM underlying_01796 FORMAT Null;
DROP TABLE underlying_01796;

View File

@ -0,0 +1,5 @@
DROP TABLE IF EXISTS underlying_01797;
CREATE TABLE underlying_01797 (key UInt64) Engine=StripeLog();
INSERT INTO FUNCTION remote('127.1', currentDatabase(), underlying_01797) SELECT toUInt64(number) FROM system.numbers LIMIT 1;
SELECT * FROM underlying_01797 FORMAT Null;
DROP TABLE underlying_01797;