Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Race Condition Between RemoveExpired() in Timer and SqliteCache.Dispose() #24

Open
Cologler opened this issue Feb 14, 2025 · 1 comment

Comments

@Cologler
Copy link

Cologler commented Feb 14, 2025

RemoveExpired() in the Timer may race with SqliteCache.Dispose(), leading to a situation where some commands or connections are added to the DbCommandPool after it has already been disposed, preventing them from being properly disposed of.

Additionally, if an object retrieved from the DbCommandPool is in the process of being disposed, an ObjectDisposedException may be thrown in the Timer callback.

Calling _cleanupTimer?.Dispose() before disposing the DbCommandPool does not guarantee that the timer callback has not already started executing.

(Translated with GPT)

@mqudsi
Copy link
Member

mqudsi commented Feb 15, 2025

Thanks for reporting this.

We'll have to use the Timer.Dispose(WaitHandle) overload to wait for all callbacks to be executed before the call returns (or else add more synchronization that we still need to safely dispose of, possibly via reference counting). This'll make the call to SqlCache.Dispose() block, so it would be good to also make it AsyncDisposable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants