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

acquireTimeout not working for idleConnections > 0 #116

Closed
lschmierer opened this issue Jun 16, 2020 · 3 comments
Closed

acquireTimeout not working for idleConnections > 0 #116

lschmierer opened this issue Jun 16, 2020 · 3 comments

Comments

@lschmierer
Copy link

When idle connections are present while the database connection gets lost, pool.getConnection() does not resolve with an error after acquireTimeout.

The reason seems to be that the pool tries to ping the server.
With default socketTimeout: 0, this runs indefinitely.

I looked into writing an integration test, but was not sure how to simulate "external connection loss".

Reproduce

  1. Create Pool.
  2. Shutdown database.
  3. Call pool.getConnection()
    => does not time out.
@rusher
Copy link
Collaborator

rusher commented Jun 30, 2020

allright, found and reproduced the issue.
Do you use some proxy between client and server ? Socket usually not stay very long in this kind of waiting state normally, but if there is some proxy.

Correction will be done quickly.

rusher added a commit that referenced this issue Jun 30, 2020
…imeout set #116

Pool option `acquireTimeout` ensure that pool.getConnection() throw an error if there is no available connection after this timeout is reached.

When connection stays in pool unused for some time (`minDelayValidation` option), pool will return those connection after a validation (PING to server). The issue is that when using proxy between client and server, socket to proxy might still be open, but proxy might be busy reconnecting server for an unknown amount of time. In those case, `acquireTimeout` is not respected, and pool.getConnection() might wait indefinitely.

New option `pingTimeout`, defaulting to 250ms is added so validation is limited in time.

Connection.ping() now has an optional Timeout parameter. If timeout is reached, promise is rejected and connection is force closed.
@lschmierer
Copy link
Author

Ah yes, makes sense.

I used xampp-vm for macOS, which runs the database in a local virtual machine.
It might virtualization that keeps the socket waiting longer than normally.

Thanks for the fix!

rusher added a commit that referenced this issue Jul 1, 2020
…imeout set #116

Pool option `acquireTimeout` ensure that pool.getConnection() throw an error if there is no available connection after this timeout is reached.

When connection stays in pool unused for some time (`minDelayValidation` option), pool will return those connection after a validation (PING to server). The issue is that when using proxy between client and server, socket to proxy might still be open, but proxy might be busy reconnecting server for an unknown amount of time. In those case, `acquireTimeout` is not respected, and pool.getConnection() might wait indefinitely.

New option `pingTimeout`, defaulting to 250ms is added so validation is limited in time.

Connection.ping() now has an optional Timeout parameter. If timeout is reached, promise is rejected and connection is force closed.
@rusher
Copy link
Collaborator

rusher commented Aug 18, 2020

closing since released in 2.4.2

@rusher rusher closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants