File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -750,7 +750,6 @@ function socketOnClose () {
750750 const websocket = this [ kWebSocket ] ;
751751
752752 this . removeListener ( 'close' , socketOnClose ) ;
753- this . removeListener ( 'data' , socketOnData ) ;
754753 this . removeListener ( 'end' , socketOnEnd ) ;
755754 this [ kWebSocket ] = undefined ;
756755
@@ -760,11 +759,16 @@ function socketOnClose () {
760759 // The close frame might not have been received or the `'end'` event emitted,
761760 // for example, if the socket was destroyed due to an error. Ensure that the
762761 // `receiver` stream is closed after writing any remaining buffered data to
763- // it.
762+ // it. If the readable side of the socket is in flowing mode then there is no
763+ // buffered data as everything has been already written and `readable.read()`
764+ // will return `null`. If instead, the socket is paused, any possible buffered
765+ // data will be read as a single chunk and emitted synchronously in a single
766+ // `'data'` event.
764767 //
765768 websocket . _socket . read ( ) ;
766769 websocket . _receiver . end ( ) ;
767770
771+ this . removeListener ( 'data' , socketOnData ) ;
768772 clearTimeout ( websocket . _closeTimer ) ;
769773
770774 if (
You can’t perform that action at this time.
0 commit comments