Skip to content

Fix listener leak on the shared port-probe server - #218

Open
faithfulojebiyi wants to merge 1 commit into
httptoolkit:mainfrom
faithfulojebiyi:fix-probe-listener-leak
Open

faithfulojebiyi wants to merge 1 commit into
httptoolkit:mainfrom
faithfulojebiyi:fix-probe-listener-leak

Conversation

@faithfulojebiyi

Copy link
Copy Markdown

probePort reuses one net.Server and adds a once('listening') and a once('error') listener per probe, but only one of the two fires, so the other stays attached. Consecutive probes of the same kind (e.g. an app repeatedly proxying to a local port with nothing on ::1) accumulate them until Node warns:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Server]. MaxListeners is 10.

and the listeners leak for the life of the process. (An error event also clears stale error listeners from earlier probes, so alternating results hide it; runs of the same result don't.)

Each handler now removes the other.

The new test/socket-util.spec.ts probes 12 free and then 12 bound ports in a row and asserts no MaxListenersExceededWarning. It fails before this change (with the warning above, for both error and listening) and passes after. test/integration/proxying/http-proxying.spec.ts still passes (59 tests).

probePort reuses one net.Server and adds a once('listening') and a
once('error') listener per probe, but only one of the two fires, so the
other stays attached. Consecutive probes of the same kind accumulate them
until Node warns MaxListenersExceededWarning. Each handler now removes the
other.
@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

2 participants