Skip to content
Permalink
Browse files
fix(local-server): addressed a possible EventEmitter memory leak when…
… restarting the local server
  • Loading branch information
jan-molak committed Jun 10, 2020
1 parent b6f7852 commit 1c0bec757b27078ba451d402a46485b4a40b735d
Showing 1 changed file with 6 additions and 2 deletions.
@@ -112,15 +112,19 @@ export class ManageALocalServer implements Ability {
*/
listen(preferredPorts: number[]): Promise<void> {
return getPort({ port: preferredPorts }).then(port => new Promise<void>((resolve, reject) => {
this.server.on('error', (error: Error & {code: string}) => {
function errorHandler(error: Error & {code: string}) {
if (error.code === 'EADDRINUSE') {
return reject(new ConfigurationError(`Server address is in use. Is there another server running on port ${ port }?`, error));
}

return reject(error);
});
}

this.server.once('error', errorHandler);

this.server.listen(port, '127.0.0.1', () => {
this.server.removeListener('error', errorHandler);

resolve();
});
}));

0 comments on commit 1c0bec7

Please sign in to comment.