Skip to content

fix: Allow removal of message listeners on utility processes - #1472

Open
timfish wants to merge 1 commit into
masterfrom
fix/utility-process-listener-removal
Open

timfish wants to merge 1 commit into
masterfrom
fix/utility-process-listener-removal

Conversation

@timfish

@timfish timfish commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1466

configureUtilityProcessIPC() replaced child.on with a Proxy that registered an anonymous wrapper around each message listener to hide the SDK's handshake message. off and removeListener compare by identity and never found the wrapper, so listeners were never removed. once broke the same way because Node's once calls on, so its wrapper was wrapped again and never removed itself. addListener and prependListener were not wrapped and received the handshake message.

The wrapping now covers all five add methods and each wrapper carries a listener property pointing at the caller's function. Node's removeListener and listeners() look through that property, so off and listeners() work without proxying them. once registers a wrapper that removes itself on the first message that is not hidden.

Unit tests cover the issue's reproduction and the once/off/listeners behaviour. The issue's script against this build leaks 0 listeners after 1,000 on/off pairs, down from 1,000. Utility process e2e tests pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

child.off('message', listener) does nothing on a utility process once the SDK is initialised

1 participant