Repository navigation
fix(js): let the anonymize worker exit after it replies - #271
Merged
karthiksathishjeemain merged 1 commit intoNov 28, 2026
Merged
karthiksathishjeemain merged 1 commit into
karthiksathishjeemain merged 1 commit into
Conversation
the worker listened with parentPort.on, so it never exited and every upload left a thread behind. it only handles one message, so use once and let it exit on its own.
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.
what was wrong
every upload to /api/anonymize starts a new worker thread, and that worker never
exits. anonymizeWorker.js listens with
parentPort.on("message", ...), which keepsthe thread alive, and the controller never terminates it. the worker only ever
handles one message, so each request leaves a thread and its heap behind.
repro on dev (start the server, then send 16 csv uploads one after another to
/api/anonymize, watching the node process):
idle: 84 MB, 13 threads
after 16 uploads: 598 MB, 33 threads, nothing is released
what i changed
parentPort.onceinstead ofparentPort.onin the worker, so the listener goes away afterthe one message and the worker exits by itself with code 0. i didn't call
worker.terminate() in the controller: it exits with code 1, and the existing exit handler
logs that as an error on every successful request.
added tests/controllers/anonymizeWorkerExit.test.js: it watches the worker the controller
starts and checks it exits with code 0, for a normal upload and for a file that can't be read
(the 400 path).
how i tested
note: the new test is in tests/controllers, so
npm testwon't pick it up until itsfile list includes that folder. run it with
npx mocha tests/controllers/anonymizeWorkerExit.test.js --exitfrom javascript_backend