From beaead41449fb898c58322dcee2aeb35d12a55a5 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 23 Oct 2020 09:40:22 -0700 Subject: [PATCH] Revert "fix(listeners): avoid "too many listeners" problem (#3931)" This holds on to process / handlers forever. --- src/server/processLauncher.ts | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.ts index 3a4d0df206b93..b19281a7a00d3 100644 --- a/src/server/processLauncher.ts +++ b/src/server/processLauncher.ts @@ -23,7 +23,6 @@ import { helper } from './helper'; import { Progress } from './progress'; import * as types from './types'; import { isUnderTest } from '../utils/utils'; -import { EventEmitter } from 'events'; export type Env = {[key: string]: string | number | boolean | undefined}; @@ -59,26 +58,6 @@ export async function gracefullyCloseAll() { await Promise.all(Array.from(gracefullyCloseSet).map(gracefullyClose => gracefullyClose().catch(e => {}))); } -class EventEmitterWrapper extends EventEmitter { - private _wrappedEvents: Set; - constructor(emitter: EventEmitter) { - super(); - this.setMaxListeners(0); - this._wrappedEvents = new Set(); - for (const method of ['addListener', 'on', 'once', 'prependListener', 'prependOnceListener'] as const) { - this[method] = (event: string | symbol, listener: (...args: any[]) => void) => { - if (!this._wrappedEvents.has(event)) { - this._wrappedEvents.add(event); - emitter.addListener(event, (...eventArgs) => this.emit(event, ...eventArgs)); - } - return super[method](event, listener); - }; - } - } -} - -const processWrapper = new EventEmitterWrapper(process); - export async function launchProcess(options: LaunchProcessOptions): Promise { const cleanup = () => helper.removeFolders(options.tempDirectories); @@ -136,9 +115,9 @@ export async function launchProcess(options: LaunchProcessOptions): Promise { + listeners.push(helper.addEventListener(process, 'SIGINT', () => { gracefullyClose().then(() => { // Give tests a chance to dispatch any async calls. if (isUnderTest()) @@ -149,9 +128,9 @@ export async function launchProcess(options: LaunchProcessOptions): Promise