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

deadpool-sqlite ConnectionWrapper is not async-safe #114

Closed
SergioBenitez opened this issue Jul 18, 2021 · 1 comment · Fixed by #115
Closed

deadpool-sqlite ConnectionWrapper is not async-safe #114

SergioBenitez opened this issue Jul 18, 2021 · 1 comment · Fixed by #115
Labels
A-sqlite Area: SQLite / deadpool-sqlite bug Category: This is a bug.

Comments

@SergioBenitez
Copy link

ConnectionWrapper wraps a rustqlite::Connection which implements a Drop that may perform synchronous I/O:

impl Drop for Connection {
    #[inline]
    fn drop(&mut self) {
        self.flush_prepared_statement_cache();
    }
}

Thus, when (the last of the clones of) ConnectionWrapper is dropped, synchronous I/O will be performed in what is surely to be an async context. This is, of course, logically incorrect behavior that can lead to quite a few problems including panics.

In general, wrapping a synchronous connection correctly (or any other I/O object) is incredibly error-prone. Please see our implementation in rocket_sync_db_pools where we've painstakingly tried to address all of the relevant issues: https://github.com/SergioBenitez/Rocket/blob/693f4f9ee50057fc735e6e7037e6dee5b485ba10/contrib/sync_db_pools/lib/src/connection.rs.

@bikeshedder
Copy link
Owner

Good catch. I didn't think of this.

I did hesitate to add any sync database drivers to deadpool for that exact reason. I should've known better than releasing a half-baked implementation of this. 😞

Please review #115 which fixes this problem. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sqlite Area: SQLite / deadpool-sqlite bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants