Eliminate possible race between LockFile() vs UnlockFile() (#7721)

Summary:
LockFile() accessing LockHoldingInfo (element of locked_files) by
reference after mutex_locked_files had been released.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7721

Reviewed By: pdillinger

Differential Revision: D25431839

Pulled By: jay-zhuang

fbshipit-source-id: eefee93f12a8016a98e2466e442af2605b3e2a5e
main
Azat Khuzhin 4 years ago committed by Facebook GitHub Bot
parent 8ff6557e7f
commit 40f2b65008
  1. 2
      env/fs_posix.cc

2
env/fs_posix.cc vendored

@ -766,9 +766,9 @@ class PosixFileSystem : public FileSystem {
// closed, all locks the process holds for that *file* are released // closed, all locks the process holds for that *file* are released
const auto it_success = locked_files.insert({fname, lhi}); const auto it_success = locked_files.insert({fname, lhi});
if (it_success.second == false) { if (it_success.second == false) {
LockHoldingInfo prev_info = it_success.first->second;
mutex_locked_files.Unlock(); mutex_locked_files.Unlock();
errno = ENOLCK; errno = ENOLCK;
LockHoldingInfo& prev_info = it_success.first->second;
// Note that the thread ID printed is the same one as the one in // Note that the thread ID printed is the same one as the one in
// posix logger, but posix logger prints it hex format. // posix logger, but posix logger prints it hex format.
return IOError("lock hold by current process, acquire time " + return IOError("lock hold by current process, acquire time " +

Loading…
Cancel
Save