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.

PR-URL: https://github.com/nodejs/node/pull/60464
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Joyee Cheung
2025-11-07 14:28:03 +01:00
committed by GitHub
parent c2d14c1514
commit 9495906f8b
3 changed files with 11 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ const {
const Buffer = require('buffer').Buffer;
const crypto = require('crypto');
const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;
const { EventEmitter } = require('events');
const { EventEmitter, once } = require('events');
const http = require('http');
const { URL } = require('internal/url');
@@ -343,13 +343,10 @@ class Client extends EventEmitter {
this.emit('ready');
};
return new Promise((resolve, reject) => {
this.once('error', reject);
this.once('ready', resolve);
httpReq.on('upgrade', handshakeListener);
httpReq.end();
});
const onReady = once(this, 'ready');
httpReq.on('upgrade', handshakeListener);
httpReq.end();
return onReady;
}
}

View File

@@ -141,6 +141,10 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
return getOutput();
},
get stderrOutput() {
return stderrOutput;
},
get rawOutput() {
return outputBuffer.join('').toString();
},

View File

@@ -31,6 +31,8 @@ const startCLI = require('../common/debugger');
} finally {
await cli.quit();
}
assert.doesNotMatch(cli.stderrOutput, /MaxListenersExceededWarning/);
}
onWaitForInitialBreak();