- Notifications
You must be signed in to change notification settings - Fork2k
fix: prevent timer resource leaks in query execution#28779
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
aqrln left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This doesn't improve anything because you're not actually cleaning the timer, just setting a boolean flag, so the callback is only going to run after the timeout expires anyway. And at that point making it conditional doesn't change anything since rejecting a resolved promise does nothing.
I don't think leaving the timers running in background is a huge problem since we'reunrefing them,queryTimeout is always small in practice, and you're going to have as many timers as there are queries one way or the other. That said, canceling them properly would be nice indeed and a marginal improvement.
What would be much more valuable IMO, is the opposite thing: cancelling the query execution when a timeout occurs instead of letting it hang in background. We could use anAbortController to send an abort signal to theQueryIntepreter, andQueryInterpreter could check ifAbortSignal is aborted before executing each step of the query plan, and throw the abort reason otherwise. We could even forward thisAbortSignal all the way to the driver adapters in case some database driver supports query cancellation.
Problem
The
Promise.racepattern withsetTimeoutin query execution was causing potential resource leaks when queries completed before timeout.Solution
Added a
timeoutClearedflag to ensure timeout promises are properly "cleared" when queries complete first.Changes
packages/query-plan-executor/src/logic/app.tsTesting
Code Example