Skip to content

Commit

Permalink
fix: catch websocket error events
Browse files Browse the repository at this point in the history
WebSockets can throw an error event that has to be captured in
node to prevent application crashing.

This seems to be crashing WebKit Linux on some of the bots with the
`ECONNRESET` error:
- https://github.com/microsoft/playwright/runs/544357239

WS-related `ECONNRESET` error discussion:
- websockets/ws#1256
  • Loading branch information
aslushnikov committed Mar 30, 2020
1 parent d9c064b commit db5ce68
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/server/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { helper } from '../helper';
import { debugError, helper } from '../helper';
import { CRBrowser } from '../chromium/crBrowser';
import * as platform from '../platform';
import * as ws from 'ws';
Expand Down Expand Up @@ -269,6 +269,8 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, port: number
session.queue!.push(parsedMessage);
});

socket.on('error', error => debugError(error));

socket.on('close', (socket as any).__closeListener = () => {
const session = socketToBrowserSession.get(socket);
if (!session || !session.sessionId)
Expand Down
4 changes: 3 additions & 1 deletion src/server/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { TimeoutError } from '../errors';
import { Events } from '../events';
import { FFBrowser } from '../firefox/ffBrowser';
import { kBrowserCloseMessageId } from '../firefox/ffConnection';
import { helper } from '../helper';
import { debugError, helper } from '../helper';
import * as platform from '../platform';
import { BrowserServer } from './browserServer';
import { BrowserArgOptions, BrowserType, LaunchOptions } from './browserType';
Expand Down Expand Up @@ -295,6 +295,8 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, port: number
pendingBrowserContextDeletions.set(seqNum, params.browserContextId);
});

socket.on('error', error => debugError(error));

socket.on('close', (socket as any).__closeListener = () => {
for (const [browserContextId, s] of browserContextIds) {
if (s === socket) {
Expand Down
4 changes: 3 additions & 1 deletion src/server/webkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as platform from '../platform';
import * as os from 'os';
import { helper } from '../helper';
import { debugError, helper } from '../helper';
import { kBrowserCloseMessageId } from '../webkit/wkConnection';
import { LaunchOptions, BrowserArgOptions, BrowserType } from './browserType';
import { ConnectionTransport, SequenceNumberMixer } from '../transport';
Expand Down Expand Up @@ -276,6 +276,8 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, port: number
pendingBrowserContextDeletions.set(seqNum, params.browserContextId);
});

socket.on('error', error => debugError(error));

socket.on('close', (socket as any).__closeListener = () => {
for (const [pageProxyId, s] of pageProxyIds) {
if (s === socket)
Expand Down

0 comments on commit db5ce68

Please sign in to comment.