Comments (11)
We're running into this issue in production.
Does anyone know a workaround that works now?
from r2d2.
I just ran into this issue - it's definitely not theoretical, and has some pretty nasty consequences: namely transactions may not be closed correctly when a thread panics. Since database locks are held until the transaction is closed, this can result in the entire system locking up indefinitely.
I believe the "most correct" solution here would be to require manually returning the connection to the pool, because using thread::panicking
is not quite correct (the connection may have been opened whilst unwinding, in which case it is safe to return).
For backwards compatibility, perhaps you could add a "discard" method and an "unwind-safe" wrapper which automatically discards the connection when dropped unless you explicitly return it to the pool.
from r2d2.
Is this in reference to a connection implementation that will be in a bad state during a panic, or is this more of a general principle of the thing?
from r2d2.
I don't have a concrete example of a connection which has broken invariants when a panic occurs if that's what you mean. I'm sure I can find one pretty easily if you really don't believe that those cases exist.
from r2d2.
The fact that I'm not aware of any instance in which this has been a problem in the last several years guides my instincts to some extent
That being said, I don't think I have a problem dropping connections that are checked back in after a panic. It can always be made configurable if that impacts someone's use case negatively.
from r2d2.
The fact that I'm not aware of any instance in which this has been a problem in the last several years
catch_unwind
has been stable for less than a year.
from r2d2.
I don't see how that's really related? Other kinds of "panic safety" like mutex poisoning has been around for quite a long time.
from r2d2.
Hm, on second thoughts, the thread::panicking
solution is probably "good enough" (tm) - the remaining functionality can be implemented on the underlying connection type using has_broken
.
from r2d2.
Can you not use RAII for your transaction management?
from r2d2.
@sfackler You mean rolling back the transaction on Drop if the drop was caused by a panic?
from r2d2.
I mean rolling back the connection on Drop if the transaction hasn't been committed: https://github.com/sfackler/rust-postgres/blob/master/tokio-postgres/src/transaction.rs#L30
from r2d2.
Related Issues (20)
- Mongodb official backend release deprecates r2d2-mongodb HOT 1
- Pass additional data to event handler HOT 1
- roadmap to v1.0.0? HOT 3
- Will r2d2 create more connections than max_size when using builder()? HOT 3
- pool.get() returns Error(None) -- best debugging strategy? HOT 1
- Is there a way to not keep idle connections? HOT 8
- `get_timeout` exceeds timeout HOT 11
- Can be used in the future such as tokio, async_std? HOT 1
- Use `compare_exchange` or `compare_exchange_weak` instead
- Is there a way to drop or close an actual connection when I'm using PooldConnection? HOT 4
- "Named" connections HOT 3
- Why example use `let pool = pool.clone()` in a for loop ? HOT 2
- Document relationship between `min_idle`, `idle_timeout` and `max_lifetime` HOT 1
- How to set timezone when linking HOT 1
- Release? HOT 1
- Allow hooking on connection get-from-pool and release-to-pool HOT 8
- Using behind proxychains HOT 1
- Seg fault with Postgres HOT 14
- Remove parking_lot dependency now that std's Mutex is faster than before HOT 3
- [Bug] CI test failure on arm HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r2d2.