From e73e83928f0ed02deac3b8d31bf34ab797191d6b Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 25 Jun 2019 00:24:52 +0200 Subject: [PATCH] msg.finished is only finished if socket has been detached --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a6724cf..5810ce0 100644 --- a/index.js +++ b/index.js @@ -65,9 +65,15 @@ function onFinished (msg, listener) { function isFinished (msg) { var socket = msg.socket + if (msg.stream) { + // Http2ServerRequest + // Http2ServerResponse + return msg.stream.closed + } + if (typeof msg.finished === 'boolean') { // OutgoingMessage - return Boolean(msg.finished || (socket && !socket.writable)) + return Boolean((!socket && msg.finished && msg.outputSize === 0) || (socket && !socket.writable)) } if (typeof msg.complete === 'boolean') {