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:
parent
e56b5be904
commit
a97f665629
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue