Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
SE7EN2028 wants to merge1 commit intoprisma:main
base:main
Choose a base branch
Loading
fromSE7EN2028:main

Conversation

@SE7EN2028
Copy link

Problem

ThePromise.race pattern withsetTimeout in query execution was causing potential resource leaks when queries completed before timeout.

Solution

Added atimeoutCleared flag to ensure timeout promises are properly "cleared" when queries complete first.

Changes

  • Modifiedpackages/query-plan-executor/src/logic/app.ts
  • Added flag-based timeout cleanup

Testing

  • Maintains identical timeout behavior for slow queries
  • Prevents timer accumulation for fast queries
  • No breaking changes

Code Example

// Before (potential resource leak):constresult=awaitPromise.race([queryInterpreter.run(queryPlan,queryable),timers.setTimeout(timeout).then(()=>{thrownewResourceLimitError('Query timeout exceeded')}),])// After (proper cleanup):lettimeoutCleared=falseconstresult=awaitPromise.race([queryInterpreter.run(queryPlan,queryable).finally(()=>{timeoutCleared=true// Mark timeout as cleared}),timers.setTimeout(timeout).then(()=>{if(!timeoutCleared){thrownewResourceLimitError('Query timeout exceeded')}}),])

Copy link
Member

@aqrlnaqrln left a 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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@aqrlnaqrlnaqrln requested changes

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@SE7EN2028@aqrln

[8]ページ先頭

©2009-2025 Movatter.jp