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

Pool drops connections if acquire is cancelled (problematic for sqlite in-memory dbs) #1869

Closed
madadam opened this issue May 17, 2022 · 2 comments · Fixed by #1901
Closed

Comments

@madadam
Copy link
Contributor

madadam commented May 17, 2022

When the future returned by Pool::acquire is cancelled, then depending on at which point it's cancelled, the connection being acquired might get dropped. This happens when the cancellation happens after the connection is removed from the internal queue but before it's returned to the caller - e.g. while it's being pinged.

This is normally not a problem as the pool can establish a new connection on the next call to acquire, but there is one use case when this becomes a problem: When using sqlite's in-memory databases - in this case the database is tied to the connection and so dropping the connection wipes out the whole database.

One possible solution to this would be to change Floating to return the connection back to the pool on drop, instead of just releasing the semaphore and dropping the connection. Not sure how hard would be to do this.

(Note this comment seems to suggest you guys are aware of this problem and plan to address it in the next version. So feel free to close this issue if it's a duplicate, however I haven't seen it reported after a quick search).

@abonander
Copy link
Collaborator

If you set .test_before_acquire(false) on PoolOptions, then it should immediately return the connection after acquiring it from the idle queue.

@madadam
Copy link
Contributor Author

madadam commented May 18, 2022

That did the trick! Thanks.

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

Successfully merging a pull request may close this issue.

2 participants