Skip to content

Commit 651d662

Browse files
committed
[fix] Call the _final() callback before destroying the stream
Ensure that `'finish'` event is emitted. Refs: nodejs/node#32780
1 parent 62f71d1 commit 651d662

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

lib/stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ function createWebSocketStream(ws, options) {
125125
if (ws._socket === null) return;
126126

127127
if (ws._socket._writableState.finished) {
128-
if (duplex._readableState.endEmitted) duplex.destroy();
129128
callback();
129+
if (duplex._readableState.endEmitted) duplex.destroy();
130130
} else {
131131
ws._socket.once('finish', function finish() {
132132
// `duplex` is not destroyed here because the `'end'` event will be

test/create-websocket-stream.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ describe('createWebSocketStream', () => {
354354

355355
duplex.on('finish', () => {
356356
events.push('finish');
357-
assert.ok(duplex.destroyed);
358357
});
359358

360359
duplex.resume();

0 commit comments

Comments
 (0)