mirror of https://github.com/facebook/rocksdb.git
Fix race condition between event listener and error handler (#12803)
Summary: Fix a race for accessing `bg_error_` after mutex is released. We make some copies before releasing to avoid this. Pull Request resolved: https://github.com/facebook/rocksdb/pull/12803 Reviewed By: cbi42 Differential Revision: D58957557 Pulled By: jowlyzhang fbshipit-source-id: 3c7369a3b8c8707aebc0044ff98288c898c05cb8
This commit is contained in:
parent
13549817af
commit
fa4ffc816c
|
@ -228,15 +228,18 @@ void EventHelpers::NotifyOnErrorRecoveryEnd(
|
|||
InstrumentedMutex* db_mutex) {
|
||||
if (!listeners.empty()) {
|
||||
db_mutex->AssertHeld();
|
||||
// Make copies before releasing mutex to avoid race.
|
||||
Status old_bg_error_cp = old_bg_error;
|
||||
Status new_bg_error_cp = new_bg_error;
|
||||
// release lock while notifying events
|
||||
db_mutex->Unlock();
|
||||
TEST_SYNC_POINT("NotifyOnErrorRecoveryEnd:MutexUnlocked:1");
|
||||
TEST_SYNC_POINT("NotifyOnErrorRecoveryEnd:MutexUnlocked:2");
|
||||
for (auto& listener : listeners) {
|
||||
BackgroundErrorRecoveryInfo info;
|
||||
info.old_bg_error = old_bg_error;
|
||||
info.new_bg_error = new_bg_error;
|
||||
listener->OnErrorRecoveryCompleted(old_bg_error);
|
||||
info.old_bg_error = old_bg_error_cp;
|
||||
info.new_bg_error = new_bg_error_cp;
|
||||
listener->OnErrorRecoveryCompleted(old_bg_error_cp);
|
||||
listener->OnErrorRecoveryEnd(info);
|
||||
info.old_bg_error.PermitUncheckedError();
|
||||
info.new_bg_error.PermitUncheckedError();
|
||||
|
|
Loading…
Reference in New Issue