Skip to content

Commit 520937c

Browse files
authored
Merge pull request #2475 from Automattic/pltfrm-1407-possible-eventemitter-memory-leak-detected-11-error
fix(wp): EventEmitter memory leak for `error` listeners
2 parents dd94c13 + b9cac2f commit 520937c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/bin/vip-wp.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ const bindStreamEvents = ( { subShellRl, commonTrackingParams, isSubShell, stdou
110110
if ( ! isSubShell ) {
111111
subShellRl.close();
112112
process.exit();
113-
return;
114113
}
115114
subShellRl.resume();
116115
subShellRl.prompt();
@@ -141,6 +140,14 @@ const getTokenForCommand = async ( appId, envId, command ) => {
141140
} );
142141
};
143142

143+
/**
144+
* Returns the error so it can be caught by the `socket.on('error')`.
145+
*
146+
* @param {Error} err
147+
* @returns {Error}
148+
*/
149+
const onSocketError = err => err;
150+
144151
const launchCommandAndGetStreams = async ( { socket, guid, inputToken, offset = 0 } ) => {
145152
const stdoutStream = IOStream.createStream();
146153
const stdinStream = IOStream.createStream();
@@ -172,10 +179,7 @@ const launchCommandAndGetStreams = async ( { socket, guid, inputToken, offset =
172179
exit.withError( `Cancel received from server: ${ message }` );
173180
} );
174181

175-
IOStream( socket ).on( 'error', err => {
176-
// This returns the error so it can be catched by the socket.on('error')
177-
return err;
178-
} );
182+
IOStream( socket ).off( 'error', onSocketError ).on( 'error', onSocketError );
179183

180184
socket.on( 'error', err => {
181185
if ( err === 'Rate limit exceeded' ) {

0 commit comments

Comments
 (0)