Repository navigation
refactor(compression): drop the terminate flag from pool removal - #12815
Closed
anhtahaylove wants to merge 2 commits into
Closed
anhtahaylove wants to merge 2 commits into
anhtahaylove wants to merge 2 commits into
Conversation
CompressionWorkerPool.finish() scheduled idle eviction with remove(slot, false), which deletes the slot from this.workers without terminating the underlying Worker. The pool then loses its only reference, so the worker thread, its MessagePort and its private heap survive for the lifetime of the process. Every burst of compression traffic separated by more than idleMs strands up to OMNI_COMPRESSION_WORKERS threads. On a 16h instance this accumulated 55 orphaned MessagePorts, 69 OS threads and 5.7GB of commit charge, while process.memoryUsage() still reported rss=660MB because V8 does not account for orphaned worker isolates. The error and shutdown paths already pass true; only the success path leaked. Fixes diegosouzapw#12812
After the idle-eviction fix, all three call sites pass terminate=true, so the parameter only exists to express a state the pool cannot safely be in: a slot deleted from this.workers while its Worker keeps running. Removing the flag makes that state unrepresentable. remove() now always terminates, which is the only correct behaviour once the pool has dropped its reference to the slot. No behavioural change on top of the previous commit.
This was referenced Sep 5, 2026
4 of 5 tasks
Contributor
Contributor
Author
|
Superseded by #13091, which carries the identical source change plus a regression test and a changelog entry. Closing this one to keep the review queue unambiguous — no need to review both. |
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.
Follow-up to #12813 — please merge that one first, as this branch is stacked on it.
Rationale
After the idle-eviction fix, all three call sites pass
terminate: true:close()truefinish()idle timertrue(wasfalse— the bug in #12813)fail()trueThe parameter now only exists to express a state the pool cannot safely be in: a slot deleted from
this.workerswhile itsWorkerkeeps running. Onceremove()has donethis.workers.delete(slot), the pool has dropped its only reference — nothing can terminate that thread afterwards. Passingfalseis not a valid option, it is a leak.Removing the flag makes that state unrepresentable, so the same bug cannot be reintroduced by a future caller.
Change
Plus the three call sites dropping their now-redundant argument.
remove()isprivate, so this is not a public API change.No behavioural change on top of #12813.
Note on the sibling pools
I checked the other two worker owners in the codebase while investigating:
open-sse/services/compression/engines/llmlingua/worker.ts—resetWorker()always callsw.terminate()src/lib/usage/callLogArtifactWriter.ts—terminateWorker()always calls.terminate()Both are singletons that route every exit path (idle,
error,exit, close) through a single teardown function, and both null out the reference before terminating. Neither has an equivalent flag, which is why neither leaked.compressionWorkerPool.tswas the only place where "remove from pool" and "stop the thread" were decoupled — this PR closes that gap.