fix: clear timeout handle in extractReferences to prevent resource leak#222
Open
fragres wants to merge 1 commit intoDeodat-Lawson:mainfrom
Open
fix: clear timeout handle in extractReferences to prevent resource leak#222fragres wants to merge 1 commit intoDeodat-Lawson:mainfrom
fragres wants to merge 1 commit intoDeodat-Lawson:mainfrom
Conversation
The setTimeout call in extractReferences was not being tracked or cleared, leaving the timer running even after the AI call completed successfully. This mirrors the pattern already used in analysisEngine.ts (callAIAnalysis), which stores the handle and clears it in a finally block. Without clearTimeout, Node keeps the timer handle alive until it fires, delaying GC of the closure and related objects when many extractions run concurrently.
|
@fragres is attempting to deploy a commit to the Timothy Lin's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extractReferencesinreferenceExtractor.tscreates asetTimeout-based race promise but never stores or clears the timer handle. When the AI call finishes before the timeout fires, the Node.js timer keeps the closure alive until it eventually triggers, delaying GC and causing unnecessary overhead — especially under concurrent load.The pattern is already correctly implemented in
callAIAnalysisinsideanalysisEngine.ts(which stores the handle and callsclearTimeoutin afinallyblock). This PR applies the same fix toreferenceExtractor.ts.Changes:
setTimeoutreturn value intimeoutHandlefinallyblock that callsclearTimeout(timeoutHandle)after thePromise.racesettlesTest plan
pnpm test)extractReferencesstill times out correctly when the AI call stalls beyondtimeoutMs