Skip to content

Commit 3201c23

Browse files
pavelfeldmanaslushnikov
authored andcommitted
Revert "fix(listeners): avoid "too many listeners" problem (#3931)" (#4222)
This holds on to process / handlers forever.
1 parent 4975cea commit 3201c23

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

src/server/processLauncher.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { helper } from './helper';
2323
import { Progress } from './progress';
2424
import * as types from './types';
2525
import { isUnderTest } from '../utils/utils';
26-
import { EventEmitter } from 'events';
2726

2827
export type Env = {[key: string]: string | number | boolean | undefined};
2928

@@ -59,26 +58,6 @@ export async function gracefullyCloseAll() {
5958
await Promise.all(Array.from(gracefullyCloseSet).map(gracefullyClose => gracefullyClose().catch(e => {})));
6059
}
6160

62-
class EventEmitterWrapper extends EventEmitter {
63-
private _wrappedEvents: Set<string | symbol>;
64-
constructor(emitter: EventEmitter) {
65-
super();
66-
this.setMaxListeners(0);
67-
this._wrappedEvents = new Set();
68-
for (const method of ['addListener', 'on', 'once', 'prependListener', 'prependOnceListener'] as const) {
69-
this[method] = (event: string | symbol, listener: (...args: any[]) => void) => {
70-
if (!this._wrappedEvents.has(event)) {
71-
this._wrappedEvents.add(event);
72-
emitter.addListener(event, (...eventArgs) => this.emit(event, ...eventArgs));
73-
}
74-
return super[method](event, listener);
75-
};
76-
}
77-
}
78-
}
79-
80-
const processWrapper = new EventEmitterWrapper(process);
81-
8261
export async function launchProcess(options: LaunchProcessOptions): Promise<LaunchResult> {
8362
const cleanup = () => helper.removeFolders(options.tempDirectories);
8463

@@ -136,9 +115,9 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
136115
cleanup().then(fulfillCleanup);
137116
});
138117

139-
const listeners = [ helper.addEventListener(processWrapper, 'exit', killProcess) ];
118+
const listeners = [ helper.addEventListener(process, 'exit', killProcess) ];
140119
if (options.handleSIGINT) {
141-
listeners.push(helper.addEventListener(processWrapper, 'SIGINT', () => {
120+
listeners.push(helper.addEventListener(process, 'SIGINT', () => {
142121
gracefullyClose().then(() => {
143122
// Give tests a chance to dispatch any async calls.
144123
if (isUnderTest())
@@ -149,9 +128,9 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
149128
}));
150129
}
151130
if (options.handleSIGTERM)
152-
listeners.push(helper.addEventListener(processWrapper, 'SIGTERM', gracefullyClose));
131+
listeners.push(helper.addEventListener(process, 'SIGTERM', gracefullyClose));
153132
if (options.handleSIGHUP)
154-
listeners.push(helper.addEventListener(processWrapper, 'SIGHUP', gracefullyClose));
133+
listeners.push(helper.addEventListener(process, 'SIGHUP', gracefullyClose));
155134
gracefullyCloseSet.add(gracefullyClose);
156135

157136
let gracefullyClosing = false;

0 commit comments

Comments
 (0)