Koka / odbc-rs

Rust ODBC FFI binding
MIT License
103 stars 31 forks source link

Send+Sync for connection #131

Open acasajus opened 4 years ago

acasajus commented 4 years ago

Looking at the docs it says that Send and Sync are not implemented for connection but in your r2d2-odbc crate it is "unsafely" implemented. Can they be implemented in this crate? Or do you allow it under r2d2 because it takes care not to share a connection amongst two threads?

Koka commented 4 years ago

Hello, thanks for your question. This needs more deep investigation because it's highly dependent on ODBC driver manager and driver itself whether it's safe to use things concurrently or not. r2d2-odbc is hacky quick'n'dirty implementation, but in this crate we try to do things more safely

pacman82 commented 4 years ago

Just a quick comment from the sideline: In general it is unsafe, because it depends on your ODBC configuration wether this is safe or not. I'd suggest to promote a connection without Send + Sync to a connection type with Send + Sync via an unsafe function.

I think the relevant configuration to look at wether this is actually safe, is the threading level. See: https://stackoverflow.com/questions/4207458/using-unixodbc-in-a-multithreaded-concurrent-setting#4207474

Threading=2 should be fine.

bbigras commented 4 years ago

I'm also interested in this. I would love to be able to use this crate with deadpool: https://github.com/bikeshedder/deadpool/issues/43

I wouldn't mind using bb8 too.

Koka commented 4 years ago

Would gladly merge PR implementing the @pacman82 idea.