Skip to content

Commit

Permalink
[fix] Do not prematurely remove the listener of the 'data' event
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jun 19, 2018
1 parent bf9b2ec commit 6046a28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/websocket.js
Expand Up @@ -750,7 +750,6 @@ function socketOnClose () {
const websocket = this[kWebSocket];

this.removeListener('close', socketOnClose);
this.removeListener('data', socketOnData);
this.removeListener('end', socketOnEnd);
this[kWebSocket] = undefined;

Expand All @@ -760,11 +759,16 @@ function socketOnClose () {
// The close frame might not have been received or the `'end'` event emitted,
// for example, if the socket was destroyed due to an error. Ensure that the
// `receiver` stream is closed after writing any remaining buffered data to
// it.
// it. If the readable side of the socket is in flowing mode then there is no
// buffered data as everything has been already written and `readable.read()`
// will return `null`. If instead, the socket is paused, any possible buffered
// data will be read as a single chunk and emitted synchronously in a single
// `'data'` event.
//
websocket._socket.read();
websocket._receiver.end();

this.removeListener('data', socketOnData);
clearTimeout(websocket._closeTimer);

if (
Expand Down

0 comments on commit 6046a28

Please sign in to comment.