fix(wk websocket): do not send messages to a closing websocket (#593)

This commit is contained in:
Dmitry Gozman 2020-01-23 10:33:05 -08:00 committed by GitHub
parent 5a67d780e5
commit 24f5f1f952
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,7 +283,12 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport) {
}
socket = s;
s.on('message', message => transport.send(Buffer.from(message).toString()));
transport.onmessage = message => s.send(message);
transport.onmessage = message => {
// We are not notified when socket starts closing, and sending messages to a closing
// socket throws an error.
if (s.readyState !== ws.CLOSING)
s.send(message);
};
s.on('close', () => {
socket = undefined;
transport.onmessage = undefined;