Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): use setMaxListeners(0) on all internal event emitters #5283

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class AndroidDevice extends EventEmitter {

constructor(android: Android, backend: DeviceBackend, model: string) {
super();
this.setMaxListeners(0);
this._android = android;
this._backend = backend;
this.model = model;
Expand Down Expand Up @@ -385,6 +386,7 @@ class AndroidBrowser extends EventEmitter {

constructor(device: AndroidDevice, socket: SocketBackend) {
super();
this.setMaxListeners(0);
this.device = device;
this._socket = socket;
this._socket.on('close', () => {
Expand Down
1 change: 1 addition & 0 deletions src/server/android/backendAdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class BufferedSocketWrapper extends EventEmitter implements SocketBackend {

constructor(command: string, socket: net.Socket) {
super();
this.setMaxListeners(0);
this._command = command;
this._socket = socket;
this._connectPromise = new Promise(f => this._socket.on('connect', f));
Expand Down
1 change: 1 addition & 0 deletions src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export abstract class Browser extends EventEmitter {

constructor(options: BrowserOptions) {
super();
this.setMaxListeners(0);
this.options = options;
}

Expand Down
1 change: 1 addition & 0 deletions src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export abstract class BrowserContext extends EventEmitter {

constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
super();
this.setMaxListeners(0);
this._browser = browser;
this._options = options;
this._browserContextId = browserContextId;
Expand Down
2 changes: 2 additions & 0 deletions src/server/chromium/crConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class CRConnection extends EventEmitter {

constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) {
super();
this.setMaxListeners(0);
this._transport = transport;
this._protocolLogger = protocolLogger;
this._browserLogsCollector = browserLogsCollector;
Expand Down Expand Up @@ -139,6 +140,7 @@ export class CRSession extends EventEmitter {

constructor(connection: CRConnection, rootSessionId: string, targetType: string, sessionId: string) {
super();
this.setMaxListeners(0);
this._connection = connection;
this._rootSessionId = rootSessionId;
this._targetType = targetType;
Expand Down
1 change: 1 addition & 0 deletions src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ElectronApplication extends EventEmitter {

constructor(browser: CRBrowser, nodeConnection: CRConnection) {
super();
this.setMaxListeners(0);
this._browserContext = browser._defaultContext as CRBrowserContext;
this._browserContext.on(BrowserContext.Events.Close, () => {
// Emit application closed after context closed.
Expand Down
2 changes: 2 additions & 0 deletions src/server/firefox/ffConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class FFConnection extends EventEmitter {

constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) {
super();
this.setMaxListeners(0);
this._transport = transport;
this._protocolLogger = protocolLogger;
this._browserLogsCollector = browserLogsCollector;
Expand Down Expand Up @@ -162,6 +163,7 @@ export class FFSession extends EventEmitter {

constructor(connection: FFConnection, targetType: string, sessionId: string, rawSend: (message: any) => void) {
super();
this.setMaxListeners(0);
this._callbacks = new Map();
this._connection = connection;
this._targetType = targetType;
Expand Down
1 change: 1 addition & 0 deletions src/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export class WebSocket extends EventEmitter {

constructor(url: string) {
super();
this.setMaxListeners(0);
this._url = url;
}

Expand Down
1 change: 1 addition & 0 deletions src/server/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export class Worker extends EventEmitter {

constructor(url: string) {
super();
this.setMaxListeners(0);
this._url = url;
this._executionContextCallback = () => {};
this._executionContextPromise = new Promise(x => this._executionContextCallback = x);
Expand Down
2 changes: 1 addition & 1 deletion src/server/supplements/recorder/recorderApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { DEFAULT_ARGS } from '../../chromium/chromium';
const readFileAsync = util.promisify(fs.readFile);

export class RecorderApp extends EventEmitter {

private _page: Page;

constructor(page: Page) {
super();
this.setMaxListeners(0);
this._page = page;
}

Expand Down
1 change: 1 addition & 0 deletions src/server/webkit/wkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class WKSession extends EventEmitter {

constructor(connection: WKConnection, sessionId: string, errorText: string, rawSend: (message: any) => void) {
super();
this.setMaxListeners(0);
this.connection = connection;
this.sessionId = sessionId;
this._rawSend = rawSend;
Expand Down
14 changes: 14 additions & 0 deletions test/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,18 @@ describe('connect', (suite, { mode }) => {
const files = fs.readdirSync(videosPath);
expect(files.some(file => file.endsWith('webm'))).toBe(true);
});

it('should be able to connect 20 times to a single server without warnings', async ({browserType, remoteServer, server}) => {
let warning = null;
const warningHandler = w => warning = w;
process.on('warning', warningHandler);

const browsers = [];
for (let i = 0; i < 20; i++)
browsers.push(await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() }));
await Promise.all([browsers.map(browser => browser.close())]);

process.off('warning', warningHandler);
expect(warning).toBe(null);
});
});