From 2d689d6a958a21446440c69f4ee2a9bf0a1e5746 Mon Sep 17 00:00:00 2001 From: Hypnosphi Date: Fri, 16 Feb 2018 23:05:05 +0300 Subject: [PATCH 1/2] RN: Add error handler on WS to fix crashing on page reload --- app/react-native/src/server/index.js | 7 +++++++ lib/channel-websocket/src/index.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/app/react-native/src/server/index.js b/app/react-native/src/server/index.js index 09e0a34284b9..34134c719a4d 100755 --- a/app/react-native/src/server/index.js +++ b/app/react-native/src/server/index.js @@ -12,6 +12,7 @@ export default class Server { this.expressApp.use(storybook(options)); this.httpServer.on('request', this.expressApp); this.wsServer = new ws.Server({ server: this.httpServer }); + // see https://github.com/websockets/ws/issues/1256#issuecomment-364996586 this.wsServer.on('connection', (s, req) => this.handleWS(s, req)); } @@ -24,6 +25,12 @@ export default class Server { } } + socket.on('error', err => { + // Ignore network errors like `ECONNRESET`, `EPIPE`, etc. + if (err.errno) return; + throw err; + }); + socket.on('message', data => { this.wsServer.clients.forEach(c => { if (!this.options.manualId || (socket.pairedId && socket.pairedId === c.pairedId)) { diff --git a/lib/channel-websocket/src/index.js b/lib/channel-websocket/src/index.js index 4d66268a6cb5..1602fd69e337 100644 --- a/lib/channel-websocket/src/index.js +++ b/lib/channel-websocket/src/index.js @@ -52,6 +52,8 @@ export class WebsocketTransport { this._handler(event); }; this._socket.onerror = e => { + // Ignore network errors like `ECONNRESET`, `EPIPE`, etc. + if (e.errno) return; logger.error('websocket: connection error', e.message); }; this._socket.onclose = e => { From f46a63731f4acd0f698138658037c79ae849ec8d Mon Sep 17 00:00:00 2001 From: Hypnosphi Date: Sat, 17 Feb 2018 01:49:36 +0300 Subject: [PATCH 2/2] Revert client changes as they aren't needed --- app/react-native/src/server/index.js | 2 +- lib/channel-websocket/src/index.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/react-native/src/server/index.js b/app/react-native/src/server/index.js index 34134c719a4d..c00d8cb05d8b 100755 --- a/app/react-native/src/server/index.js +++ b/app/react-native/src/server/index.js @@ -12,7 +12,6 @@ export default class Server { this.expressApp.use(storybook(options)); this.httpServer.on('request', this.expressApp); this.wsServer = new ws.Server({ server: this.httpServer }); - // see https://github.com/websockets/ws/issues/1256#issuecomment-364996586 this.wsServer.on('connection', (s, req) => this.handleWS(s, req)); } @@ -25,6 +24,7 @@ export default class Server { } } + // see https://github.com/websockets/ws/issues/1256#issuecomment-364988689 socket.on('error', err => { // Ignore network errors like `ECONNRESET`, `EPIPE`, etc. if (err.errno) return; diff --git a/lib/channel-websocket/src/index.js b/lib/channel-websocket/src/index.js index 1602fd69e337..4d66268a6cb5 100644 --- a/lib/channel-websocket/src/index.js +++ b/lib/channel-websocket/src/index.js @@ -52,8 +52,6 @@ export class WebsocketTransport { this._handler(event); }; this._socket.onerror = e => { - // Ignore network errors like `ECONNRESET`, `EPIPE`, etc. - if (e.errno) return; logger.error('websocket: connection error', e.message); }; this._socket.onclose = e => {