Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
debugger: fix event listener leak in the run command
It should remove both the error and the ready event listeners
attached when either of them fires, instead of removing only
the one whose corresponding event fires, otherwise the other
event listener will always get leaked.
  • Loading branch information
joyeecheung committed Oct 28, 2025
commit 5ff338f4d8f9d26bc5bd4480ceeb2b3e482f08e5
16 changes: 14 additions & 2 deletions lib/internal/debugger/inspect_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,20 @@ class Client extends EventEmitter {
};

return new Promise((resolve, reject) => {
this.once('error', reject);
this.once('ready', resolve);
const tearDown = () => {
this.removeListener('ready', onReady);
this.removeListener('error', onError);
};
const onError = (err) => {
tearDown();
reject(err);
};
const onReady = () => {
tearDown();
resolve();
};
this.once('error', onError);
this.once('ready', onReady);
Comment thread
joyeecheung marked this conversation as resolved.
Outdated

httpReq.on('upgrade', handshakeListener);
httpReq.end();
Expand Down
4 changes: 4 additions & 0 deletions test/common/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
return getOutput();
},

get stderrOutput() {
return stderrOutput;
},

get rawOutput() {
return outputBuffer.join('').toString();
},
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-debugger-restart-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const startCLI = require('../common/debugger');
} finally {
await cli.quit();
}

assert.doesNotMatch(cli.stderrOutput, /MaxListenersExceededWarning/);
}

onWaitForInitialBreak();
Expand Down
Loading