Guard against small window where sending a message can crash the packager

Reviewed By: davidaurelio

Differential Revision: D4541015

fbshipit-source-id: 025039c593f7f0f6e40f5fd38ccc07e50f7d04b0
This commit is contained in:
Max Sherman 2017-02-10 09:28:23 -08:00 committed by Facebook Github Bot
parent e56b5be904
commit a97f665629
1 changed files with 9 additions and 1 deletions

View File

@ -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) {