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

acquire times out if called after destroy #81

Open
joshkel opened this issue Oct 29, 2024 · 0 comments
Open

acquire times out if called after destroy #81

joshkel opened this issue Oct 29, 2024 · 0 comments

Comments

@joshkel
Copy link

joshkel commented Oct 29, 2024

I'm not certain whether this is considered a bug in Knex, Tarn, or my code, but I'll start here.

I noticed that one of our programs sometimes timed out on exit. From what I can tell via debugging, it happens if the program attempts to exit early while certain database operations are going on asynchronously. This can result in one of the not-yet-canceled async operations calling acquire after destroy is called. The problem appears to be caused by the interaction of Tarn's Pool.acquire function and _tryAcquireOrCreate functions: _tryAcquireOrCreate exits early if the pool has been destroyed, but that only occurs after acquire has already created the pendingAcquire timeout, so the program appears to hang until that acquire timeout has elapsed.

Possible solutions:

  • PendingOperation's timeout calls unref on its timer so that a pending operation timeout by itself can't keep the Node.js runtime alive.
  • Pool.acquire checks this.destroyed before doing anything. If the pool has been destroyed, it rejects with an appropriate error.

Unref'ing the timer could risk unwanted effects, but adding a destroyed check to acquire seems reasonable and consistent.

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

1 participant