Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,15 @@ class Http2Stream extends Duplex {
});
}
}

// A write in flight may never get its native completion callback once the
// stream tears down; settle it so the Writable can clean up.
if (state.writeCb !== null) {
const writeCb = state.writeCb;
state.writeCb = null;
state.writePending = 0;
writeCb(err);
}
callback(err);
}
// The Http2Stream can be destroyed if it has closed and if the readable
Expand Down
14 changes: 12 additions & 2 deletions test/parallel/test-http2-close-while-writing.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ server.on('session', common.mustCall(function(session) {
stream.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ABORTED');
}));
stream.resume();

// Every write dispatched before close must have its callback invoked.
let writes = 0;
let writeCallbacks = 0;
stream.on('data', function() {
this.write(Buffer.alloc(1));
writes++;
this.write(Buffer.alloc(1), () => {
writeCallbacks++;
});
process.nextTick(() => client_stream.destroy());
});
stream.on('close', common.mustCall(() => {
assert.strictEqual(writeCallbacks, writes);
}));
stream.resume();
}));
}));

Expand Down
Loading