Skip to content

Commit 59012f8

Browse files
committed
bug fix: do not throw exception with RedMutex::unlock. #659
1 parent 84f37e9 commit 59012f8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/sw/redis++/patterns/redlock.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,12 @@ void RedMutexImpl::unlock() {
359359

360360
if (!_locked()) {
361361
// If `lock` is not called yet, the behavior is undefined.
362-
throw Error("RedMutex is not locked");
362+
// throw Error("RedMutex is not locked");
363+
// If the mutex is not locked, return without throwing exception.
364+
// Because if the background lock-entending thread fails and resets
365+
// the mutex, i.e. unlocks it, we'll throw exception in unlock, which
366+
// might cause std::terminate. Check issue #659 for detail.
367+
return;
363368
}
364369

365370
try {

0 commit comments

Comments
 (0)