Skip to content

Commit b072a03

Browse files
committed
Protect against double Dispose() issues
If the underlying timer were already disposed and we tried to dispose it again, the subsequent wait would block indefinitely.
1 parent 95176b5 commit b072a03

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

SqliteCache/SqliteCache.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ public void Dispose()
7171
// EventWaitHandle.Set(SafeWaitHandle) method, which is just a wrapper around Kernel32's
7272
// SetEvent() -- all of which is to say, we can't use a ManualResetEventSlim here.
7373
using var resetEvent = new ManualResetEvent(false);
74-
_cleanupTimer.Dispose(resetEvent);
75-
resetEvent.WaitOne();
74+
// If the timer has already been disposed, it'll return false immediately without setting the
75+
// event. Since we don't really protect against our own .Dispose() method being called twice
76+
// (maybe in a race), we should handle this eventuality.
77+
if (_cleanupTimer.Dispose(resetEvent))
78+
{
79+
resetEvent.WaitOne();
80+
}
7681
}
7782
Commands.Dispose();
7883

0 commit comments

Comments
 (0)