This slightly alters the behaviour of session close by first using .end() on a session socket to finish writing the data and only then calls .destroy() to make sure the Readable side is closed. This allows the socket to finish transmitting data, receive proper FIN packet and avoid ECONNRESET errors upon graceful close. onStreamClose now directly calls stream.destroy() instead of kMaybeDestroy because the latter will first check that the stream has writableFinished set. And that may not be true as we have just (synchronously) called .end() on the stream if it was not closed and that doesn't give it enough time to finish. Furthermore there is no point in waiting for 'finish' as the other party have already closed the stream and we won't be able to write anyway. This also changes a few tests to correctly handle graceful session close. This includes: * not reading request data (on client side) * not reading push stream data (on client side) * relying on socket.destroy() (on client) to finish server session due to the destroy of the socket without closing the server session. As the goaway itself is *not* a session close. Added few 'close' event mustCall checks. PR-URL: https://github.com/nodejs/node/pull/30854 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const http2 = require('http2');
|
|
const v8 = require('v8');
|
|
|
|
// Regression test for https://github.com/nodejs/node/issues/28088:
|
|
// Verify that Http2Settings and Http2Ping objects don't reference the session
|
|
// after it is destroyed, either because they are detached from it or have been
|
|
// destroyed themselves.
|
|
|
|
for (const variant of ['ping', 'settings']) {
|
|
const server = http2.createServer();
|
|
server.on('session', common.mustCall((session) => {
|
|
if (variant === 'ping') {
|
|
session.ping(common.expectsError({
|
|
code: 'ERR_HTTP2_PING_CANCEL'
|
|
}));
|
|
} else {
|
|
session.settings(undefined, common.mustNotCall());
|
|
}
|
|
|
|
session.on('close', common.mustCall(() => {
|
|
v8.getHeapSnapshot().resume();
|
|
server.close();
|
|
}));
|
|
session.destroy();
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = http2.connect(`http://localhost:${server.address().port}`,
|
|
common.mustCall());
|
|
client.on('error', (err) => {
|
|
// We destroy the session so it's possible to get ECONNRESET here.
|
|
if (err.code !== 'ECONNRESET')
|
|
throw err;
|
|
});
|
|
}));
|
|
}
|