Skip to content

Commit

Permalink
avoid throwing exception in RedMutex::unlock. Check issue sewenew#563
Browse files Browse the repository at this point in the history
…for detail.
  • Loading branch information
sewenew committed Jun 22, 2024
1 parent aadd872 commit 202b36b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sw/redis++/patterns/redlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,19 @@ void RedMutexImpl::unlock() {
std::lock_guard<std::mutex> lock(_mtx);

if (!_locked()) {
// If `lock` is not called yet, the behavior is undefined.
throw Error("RedMutex is not locked");
}

try {
_unlock(_lock_id);
} catch (...) {
_reset();
throw;
// We cannot throw exception in `unlock`,
// because normally we call unlock in the destructor of `std::lock_guard` or `std::unique_lock`.
// If we throw exception, the application code terminates.
// Check issue #563 for detail.
//_reset();
//throw;
}

_reset();
Expand Down

0 comments on commit 202b36b

Please sign in to comment.