Skip to content

Commit 54421e0

Browse files
joyeecheungaduh95
authored andcommitted
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: #60464 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 185f6e9 commit 54421e0

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

‎lib/internal/debugger/inspect_client.js‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const{
1313
constBuffer=require('buffer').Buffer;
1414
constcrypto=require('crypto');
1515
const{ERR_DEBUGGER_ERROR}=require('internal/errors').codes;
16-
const{ EventEmitter }=require('events');
16+
const{ EventEmitter, once}=require('events');
1717
consthttp=require('http');
1818
const{URL}=require('internal/url');
1919

@@ -343,13 +343,10 @@ class Client extends EventEmitter{
343343
this.emit('ready');
344344
};
345345

346-
returnnewPromise((resolve,reject)=>{
347-
this.once('error',reject);
348-
this.once('ready',resolve);
349-
350-
httpReq.on('upgrade',handshakeListener);
351-
httpReq.end();
352-
});
346+
constonReady=once(this,'ready');
347+
httpReq.on('upgrade',handshakeListener);
348+
httpReq.end();
349+
returnonReady;
353350
}
354351
}
355352

‎test/common/debugger.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ function startCLI(args, flags = [], spawnOpts ={}, opts ={randomPort: true })
141141
returngetOutput();
142142
},
143143

144+
getstderrOutput(){
145+
returnstderrOutput;
146+
},
147+
144148
getrawOutput(){
145149
returnoutputBuffer.join('').toString();
146150
},

‎test/parallel/test-debugger-restart-message.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const startCLI = require('../common/debugger');
3131
}finally{
3232
awaitcli.quit();
3333
}
34+
35+
assert.doesNotMatch(cli.stderrOutput,/MaxListenersExceededWarning/);
3436
}
3537

3638
onWaitForInitialBreak();

0 commit comments

Comments
(0)