Skip to content

process.listenerCount(event, listener) reports incorrect counts under CLI #822

Description

@ShiroKSH

Description

The CLI installs hidden SIGINT and SIGTERM relay listeners and wraps process.listenerCount() so those internal listeners are not visible. The wrapper currently subtracts one from every count for those signals, including the listenerCount(eventName, listener) overload and cases where the hidden listener has already been removed.

Reproduction

const handler = () => {};
process.on('SIGINT', handler);

setTimeout(() => {
	console.log(process.listenerCount('SIGINT', handler));
	process.removeAllListeners('SIGINT');
	console.log(process.listenerCount('SIGINT'));
}, 100);

With Node v24.18.0:

$ node repro.js
1
0

With the current tsx master (5828ffe):

$ tsx repro.js
0
-1

Expected behavior

Specific user-listener counts should match Node, aggregate counts should never become negative, and the internal relay listener should remain hidden while it is installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions