@@ -1238,22 +1238,23 @@ the value is `undefined`, the stream is not yet ready for use.
12381238
12391239##### Destruction
12401240
1241- All [ ` Http2Stream ` ] [ ] instances are destroyed either when:
1241+ All [ ` Http2Stream ` ] [ ] instances are destroyed when one of the following
1242+ happens:
12421243
1243- * An ` RST_STREAM ` frame for the stream is received by the connected peer,
1244- and (for client streams only) pending data has been read.
1245- * The ` http2stream.close() ` method is called, and (for client streams only)
1246- pending data has been read.
1247- * The ` http2stream.destroy() ` or ` http2session.destroy() ` methods are called.
1244+ * Both sides send ` END_STREAM ` (a clean exchange).
1245+ * The peer sends an ` RST_STREAM ` frame.
1246+ * ` http2stream.close() ` , ` http2stream.destroy() ` , or ` http2session.destroy() `
1247+ is called locally.
12481248
1249- When an ` Http2Stream ` instance is destroyed, an attempt will be made to send an
1250- ` RST_STREAM ` frame to the connected peer.
1249+ For clean exchanges and clean cancels, the destroy is deferred until any
1250+ pending ` 'end' ` and ` 'finish' ` events have fired. When destroyed, an
1251+ attempt is made to send an ` RST_STREAM ` frame to the connected peer if
1252+ one hasn't already been sent.
12511253
1252- When the ` Http2Stream ` instance is destroyed, the ` 'close' ` event will
1253- be emitted. Because ` Http2Stream ` is an instance of ` stream.Duplex ` , the
1254- ` 'end' ` event will also be emitted if the stream data is currently flowing.
1255- The ` 'error' ` event may also be emitted if ` http2stream.destroy() ` was called
1256- with an ` Error ` passed as the first argument.
1254+ ` 'close' ` is always emitted on destroy. ` 'end' ` and ` 'finish' ` fire if
1255+ their respective halves completed before destroy. ` 'error' ` fires when
1256+ the destroy carries an error — either via ` http2stream.destroy(err) ` ,
1257+ or when the peer reset the stream before sending ` END_STREAM ` .
12571258
12581259After the ` Http2Stream ` has been destroyed, the ` http2stream.destroyed `
12591260property will be ` true ` and the ` http2stream.rstCode ` property will specify the
@@ -1264,14 +1265,18 @@ destroyed.
12641265
12651266<!-- YAML
12661267added: v8.4.0
1268+ changes:
1269+ - version: REPLACEME
1270+ pr-url: https://github.com/nodejs/node/pull/63249
1271+ description: Documentation-only deprecation.
12671272-->
12681273
1269- The ` 'aborted' ` event is emitted whenever a ` Http2Stream ` instance is
1270- abnormally aborted in mid-communication.
1271- Its listener does not expect any arguments.
1274+ > Stability: 0 - Deprecated. Use ` 'close' ` and ` 'error' ` plus
1275+ > ` stream.destroyed ` .
12721276
1273- The ` 'aborted' ` event will only be emitted if the ` Http2Stream ` writable side
1274- has not been ended.
1277+ Emitted when an ` Http2Stream ` is closed before the writable side has
1278+ been ended (via ` .end() ` or auto-ended via ` respond({ endStream: true }) ` ).
1279+ Listeners receive no arguments.
12751280
12761281#### Event: ` 'close' `
12771282
@@ -1283,19 +1288,29 @@ The `'close'` event is emitted when the `Http2Stream` is destroyed. Once
12831288this event is emitted, the ` Http2Stream ` instance is no longer usable.
12841289
12851290The HTTP/2 error code used when closing the stream can be retrieved using
1286- the ` http2stream.rstCode ` property. If the code is any value other than
1287- ` NGHTTP2_NO_ERROR ` (` 0 ` ), an ` 'error' ` event will have also been emitted.
1291+ the ` http2stream.rstCode ` property.
12881292
12891293#### Event: ` 'error' `
12901294
12911295<!-- YAML
12921296added: v8.4.0
1297+ changes:
1298+ - version: REPLACEME
1299+ pr-url: https://github.com/nodejs/node/pull/63249
1300+ description: >-
1301+ Also emitted on peer-initiated resets that arrive before
1302+ `END_STREAM` (`ERR_HTTP2_STREAM_ABORTED` for clean codes,
1303+ `ERR_HTTP2_STREAM_ERROR` otherwise). Locally-initiated resets
1304+ without an explicit error remain silent.
12931305-->
12941306
12951307* ` error ` {Error}
12961308
1297- The ` 'error' ` event is emitted when an error occurs during the processing of
1298- an ` Http2Stream ` .
1309+ Emitted when an error occurs processing the ` Http2Stream ` . This includes
1310+ peer-initiated resets that arrive before the readable side has been
1311+ fully delivered: a clean reset code (` NGHTTP2_NO_ERROR ` or
1312+ ` NGHTTP2_CANCEL ` ) surfaces as [ ` ERR_HTTP2_STREAM_ABORTED ` ] [ ] , any other
1313+ code as [ ` ERR_HTTP2_STREAM_ERROR ` ] [ ] .
12991314
13001315#### Event: ` 'frameError' `
13011316
@@ -1378,8 +1393,8 @@ added: v8.4.0
13781393
13791394* Type: {boolean}
13801395
1381- Set to ` true ` if the ` Http2Stream ` instance was aborted abnormally. When set,
1382- the ` 'aborted' ` event will have been emitted.
1396+ ` true ` if the ` Http2Stream ` was closed while the writable side was
1397+ still open. When set, the ` 'aborted' ` event was emitted.
13831398
13841399#### ` http2stream.bufferSize `
13851400
@@ -1723,6 +1738,13 @@ stream.on('push', (headers, flags) => {
17231738
17241739<!-- YAML
17251740added: v8.4.0
1741+ changes:
1742+ - version: REPLACEME
1743+ pr-url: https://github.com/nodejs/node/pull/63249
1744+ description: >-
1745+ If no `'response'` listener is attached when the response headers
1746+ arrive, the response body is now silently discarded - matching
1747+ the `lib/http` client behaviour.
17261748-->
17271749
17281750* ` headers ` {HTTP/2 Headers Object}
@@ -1744,6 +1766,16 @@ req.on('response', (headers, flags) => {
17441766});
17451767```
17461768
1769+ If no ` 'response' ` listener is attached at the moment the response
1770+ arrives, the response body will be entirely discarded (the stream is
1771+ silently resumed). However, if a ` 'response' ` listener is added, the
1772+ data from the response object ** must** be consumed — either by calling
1773+ ` response.read() ` whenever there is a ` 'readable' ` event, by adding a
1774+ ` 'data' ` handler, or by calling the ` .resume() ` method. Until the data
1775+ is consumed, the ` 'end' ` event will not fire. Also, until the data is
1776+ read, it will consume memory that can eventually lead to a "process
1777+ out of memory" error.
1778+
17471779``` cjs
17481780const http2 = require (' node:http2' );
17491781const client = http2 .connect (' https://localhost' );
@@ -4035,11 +4067,8 @@ data.
40354067added: v8.4.0
40364068-->
40374069
4038- The ` 'aborted' ` event is emitted whenever a ` Http2ServerRequest ` instance is
4039- abnormally aborted in mid-communication.
4040-
4041- The ` 'aborted' ` event will only be emitted if the ` Http2ServerRequest ` writable
4042- side has not been ended.
4070+ The ` 'aborted' ` event is emitted whenever a ` Http2ServerRequest ` instance
4071+ is closed while the underlying writable side is still open.
40434072
40444073#### Event: ` 'close' `
40454074
@@ -5050,6 +5079,8 @@ you need to implement any fall-back behavior yourself.
50505079[ `'unknownProtocol'` ] : #event-unknownprotocol
50515080[ `ClientHttp2Stream` ] : #class-clienthttp2stream
50525081[ `Duplex` ] : stream.md#class-streamduplex
5082+ [ `ERR_HTTP2_STREAM_ABORTED` ] : errors.md#err_http2_stream_aborted
5083+ [ `ERR_HTTP2_STREAM_ERROR` ] : errors.md#err_http2_stream_error
50535084[ `Http2ServerRequest` ] : #class-http2http2serverrequest
50545085[ `Http2ServerResponse` ] : #class-http2http2serverresponse
50555086[ `Http2Session` and Sockets ] : #http2session-and-sockets
0 commit comments