Skip to content

Commit

Permalink
[fix] Call the _final() callback before destroying the stream
Browse files Browse the repository at this point in the history
Ensure that `'finish'` event is emitted.

Refs: nodejs/node#32780
  • Loading branch information
th37rose committed Apr 22, 2020
1 parent 60e0679 commit 41f04dd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion lib/stream.js
Expand Up @@ -125,8 +125,8 @@ function createWebSocketStream(ws, options) {
if (ws._socket === null) return;

if (ws._socket._writableState.finished) {
if (duplex._readableState.endEmitted) duplex.destroy();
callback();
if (duplex._readableState.endEmitted) duplex.destroy();
} else {
ws._socket.once('finish', function finish() {
// `duplex` is not destroyed here because the `'end'` event will be
Expand Down
1 change: 0 additions & 1 deletion test/create-websocket-stream.test.js
Expand Up @@ -354,7 +354,6 @@ describe('createWebSocketStream', () => {

duplex.on('finish', () => {
events.push('finish');
assert.ok(duplex.destroyed);
});

duplex.resume();
Expand Down

0 comments on commit 41f04dd

Please sign in to comment.