Comments (6)
I've been diving into this a bit more and I now understand why Mobc can reach a point of dropping connections and deadlocking.
The issue is happening over here https://github.com/importcjj/mobc/blob/master/src/lib.rs#L664
First some context, in our situation, we can have a lot of concurrent requests (over 1000) for a connection from the connection pool. The connection pool will only have a small number of connections for example 10. All the waiting requests have a oneshot channel created, with the Sender added to a Queue over here https://github.com/importcjj/mobc/blob/master/src/lib.rs#L542
What can happen then is that all those waiting requests are destroyed, this happens in the case when those connection requests are coming from web requests that have been aborted. So now the conn_requests
queue has over 1000 channel Senders to Receivers that have been dropped.
Now when an active connection is returned to the pool, what is supposed to happen is that mobc will go through the list of Senders and try and send the connection to a waiting Receiver. And if the Receiver has been cancelled or dropped, the connection is returned and another Sender is tried until it finds a Sender with a waiting Receiver. This is the code I mentioned earlier https://github.com/importcjj/mobc/blob/master/src/lib.rs#L664
However, when there are a large number of Receivers that have been dropped, this doesn't seem to work and the connection gets accidentally dropped. The internals.num_open
is not decremented at this point. So Mobc thinks it still has active connections when in fact it does not. So it doesn't create new connections or have any connections to pass to any new connection requests.
I have an idea to solve this. But it would involve replacing the channels with a Semaphore
. This would be similar to how deadpool works https://github.com/bikeshedder/deadpool/ I've tested it and it works with Mobc. But it would be quite a large change.
The reason the move to a Semaphore
would be better is that when a connection is returned to the pool, there is no chance of it being dropped. It would be added to the list of free_conns
. The oneshot channels will be replaced waiting for access to the semaphore. So if the request is cancelled, another request can grab the connection and there is no chance of it being accidentally lost.
from mobc.
To conclude this in case someone else comes across this. We are hosting a forked Mobc with fixes for this issue over here https://github.com/prisma/mobc
from mobc.
Hello,
We are experiencing exactly same issues on Prisma connection pool.
The application is a backend api developed with NestJS.
Could someone please explain how to implemented this fix with mobc please ?
Thanks.
from mobc.
hi @importcjj have you had a chance to look at this issue. Any ideas or suggestions I can look at?
from mobc.
@w8ze-devel can you open a ticket on the prisma repository to track this.
from mobc.
The latest 0.8.1 release fixes this.
from mobc.
Related Issues (20)
- redis::cmd.query_async does not work with mobc pool HOT 3
- Possible pool depletion and elevated number of timeouts HOT 1
- Adding Support for Redis Cluster Async HOT 1
- Pool should check for max idle lifetime in cleaner
- Incompatible with latest stable actix-web HOT 4
- Mobc should report errors HOT 1
- New features require- Provide an Async function callback when deleting a Connection
- Access to mobc
- mobc-postgres page on crates.io links to archived repository HOT 1
- Metrics related to opened connections are registered incorrectly HOT 1
- Allow use of latest `redis` patch release HOT 1
- Please release new version of `mobc-redis` HOT 2
- Configuring a `Pool` for unlimited open connections will result in no connection reuse HOT 3
- `mobc_pool_connections_idle` reports "connection limit" on start, and "connections left to connection limit" later HOT 6
- Debug for Pool struct HOT 5
- Metrics crate needs to be bumped to fix ahash compilation failure on Rust Nightly HOT 2
- `mobc-redis` need update
- Why weren't the previous two connections reused, but instead two new connections were created?
- max lifetime does not work
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 mobc.