Giter VIP home page Giter VIP logo

Comments (6)

garrensmith avatar garrensmith commented on June 5, 2024 24

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.

garrensmith avatar garrensmith commented on June 5, 2024 21

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.

w8ze-devel avatar w8ze-devel commented on June 5, 2024 9

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.

garrensmith avatar garrensmith commented on June 5, 2024

hi @importcjj have you had a chance to look at this issue. Any ideas or suggestions I can look at?

from mobc.

garrensmith avatar garrensmith commented on June 5, 2024

@w8ze-devel can you open a ticket on the prisma repository to track this.

from mobc.

garrensmith avatar garrensmith commented on June 5, 2024

The latest 0.8.1 release fixes this.

from mobc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.