Skip to content

Commit

Permalink
Guard against small window where sending a message can crash the pack…
Browse files Browse the repository at this point in the history
…ager

Reviewed By: davidaurelio

Differential Revision: D4541015

fbshipit-source-id: 025039c593f7f0f6e40f5fd38ccc07e50f7d04b0
  • Loading branch information
johnislarry authored and facebook-github-bot committed Feb 10, 2017
1 parent e56b5be commit a97f665
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion local-cli/server/util/inspectorProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ class Device {

_send(message: Event) {
debug('-> device', this._id, message);
this._socket.send(JSON.stringify(message));
// This try/catch is unfortunate, but there is a small window where a message can be sent
// 1. after the socket is closed, and
// 2. before the callback for the 'close' event on the socket is run.
// Since we don't want the packager to crash in this situation, we have to guard against this.
try {
this._socket.send(JSON.stringify(message));
} catch (err) {
debug('Error sending', err);
}
}

_onMessage(json: string) {
Expand Down

0 comments on commit a97f665

Please sign in to comment.