|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | +const assert = require('assert'); |
| 7 | +const h2 = require('http2'); |
| 8 | + |
| 9 | +// Regression test for https://github.com/nodejs/node/issues/56627 |
| 10 | +// When a client stream's writable side is already ended (e.g. GET request) |
| 11 | +// and the server destroys the session, the client stream should emit an |
| 12 | +// error event with RST code NGHTTP2_CANCEL, since the 'aborted' event |
| 13 | +// cannot be emitted when the writable side is already ended. |
| 14 | + |
| 15 | +{ |
| 16 | + const server = h2.createServer(); |
| 17 | + server.on('stream', common.mustCall((stream) => { |
| 18 | + stream.session.destroy(); |
| 19 | + })); |
| 20 | + |
| 21 | + server.listen(0, common.mustCall(() => { |
| 22 | + const client = h2.connect(`http://localhost:${server.address().port}`); |
| 23 | + |
| 24 | + client.on('close', common.mustCall(() => { |
| 25 | + server.close(); |
| 26 | + })); |
| 27 | + |
| 28 | + const req = client.request(); |
| 29 | + |
| 30 | + req.on('error', common.mustCall((err) => { |
| 31 | + assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR'); |
| 32 | + assert.match(err.message, /NGHTTP2_CANCEL/); |
| 33 | + })); |
| 34 | + |
| 35 | + req.on('aborted', common.mustNotCall()); |
| 36 | + |
| 37 | + req.on('close', common.mustCall(() => { |
| 38 | + assert.strictEqual(req.rstCode, h2.constants.NGHTTP2_CANCEL); |
| 39 | + })); |
| 40 | + |
| 41 | + req.resume(); |
| 42 | + })); |
| 43 | +} |
0 commit comments