| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7a2458 commit 2b868e8
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1253,6 +1253,13 @@ Emitted when a stream is created on the server. | |||
| 1253 | 1253 | ||
| 1254 | 1254 | Emitted when a stream is started on the server. | |
| 1255 | 1255 | ||
| 1256 | + `http2.server.stream.error` | ||
| 1257 | + | ||
| 1258 | + * `stream` {ServerHttp2Stream} | ||
| 1259 | + * `error` {Error} | ||
| 1260 | + | ||
| 1261 | + Emitted when an error occurs during the processing of a stream on the server. | ||
| 1262 | + | ||
| 1256 | 1263 | #### Modules | |
| 1257 | 1264 | ||
| 1258 | 1265 | > Stability: 1 - Experimental | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,6 +192,7 @@ const onClientStreamFinishChannel = dc.channel('http2.client.stream.finish'); | |||
| 192 | 192 | const onClientStreamCloseChannel = dc.channel('http2.client.stream.close'); | |
| 193 | 193 | const onServerStreamCreatedChannel = dc.channel('http2.server.stream.created'); | |
| 194 | 194 | const onServerStreamStartChannel = dc.channel('http2.server.stream.start'); | |
| 195 | + const onServerStreamErrorChannel = dc.channel('http2.server.stream.error'); | ||
| 195 | 196 | ||
| 196 | 197 | let debug = require('internal/util/debuglog').debuglog('http2', (fn) => { | |
| 197 | 198 | debug = fn; | |
@@ -2453,13 +2454,20 @@ class Http2Stream extends Duplex { | |||
| 2453 | 2454 | setImmediate(() => { | |
| 2454 | 2455 | session[kMaybeDestroy](); | |
| 2455 | 2456 | }); | |
| 2456 | - if (err && | ||
| 2457 | - session[kType] === NGHTTP2_SESSION_CLIENT && | ||
| 2458 | - onClientStreamErrorChannel.hasSubscribers) { | ||
| 2459 | - onClientStreamErrorChannel.publish({ | ||
| 2460 | - stream: this, | ||
| 2461 | - error: err, | ||
| 2462 | - }); | ||
| 2457 | + if (err) { | ||
| 2458 | + if (session[kType] === NGHTTP2_SESSION_CLIENT) { | ||
| 2459 | + if (onClientStreamErrorChannel.hasSubscribers) { | ||
| 2460 | + onClientStreamErrorChannel.publish({ | ||
| 2461 | + stream: this, | ||
| 2462 | + error: err, | ||
| 2463 | + }); | ||
| 2464 | + } | ||
| 2465 | + } else if (onServerStreamErrorChannel.hasSubscribers) { | ||
| 2466 | + onServerStreamErrorChannel.publish({ | ||
| 2467 | + stream: this, | ||
| 2468 | + error: err, | ||
| 2469 | + }); | ||
| 2470 | + } | ||
| 2463 | 2471 | } | |
| 2464 | 2472 | callback(err); | |
| 2465 | 2473 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,53 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + if (!common.hasCrypto) | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + | ||
| 7 | + // This test ensures that the built-in HTTP/2 diagnostics channels are reporting | ||
| 8 | + // the diagnostics messages for the 'http2.server.stream.error' channel when | ||
| 9 | + // an error occurs during the processing of a ServerHttp2Stream. | ||
| 10 | + | ||
| 11 | + const assert = require('assert'); | ||
| 12 | + const dc = require('diagnostics_channel'); | ||
| 13 | + const http2 = require('http2'); | ||
| 14 | + const { Duplex } = require('stream'); | ||
| 15 | + | ||
| 16 | + let expectedError = null; | ||
| 17 | + | ||
| 18 | + dc.subscribe('http2.server.stream.error', common.mustCall(({ stream, error }) => { | ||
| 19 | + // Since ServerHttp2Stream is not exported from any module, this just checks | ||
| 20 | + // if the stream is an instance of Duplex and the constructor name is | ||
| 21 | + // 'ServerHttp2Stream'. | ||
| 22 | + assert.ok(stream instanceof Duplex); | ||
| 23 | + assert.strictEqual(stream.constructor.name, 'ServerHttp2Stream'); | ||
| 24 | + assert.strictEqual(stream.closed, true); | ||
| 25 | + assert.strictEqual(stream.destroyed, true); | ||
| 26 | + | ||
| 27 | + assert.ok(error); | ||
| 28 | + assert.strictEqual(error, expectedError); | ||
| 29 | + })); | ||
| 30 | + | ||
| 31 | + const server = http2.createServer(); | ||
| 32 | + | ||
| 33 | + server.on('stream', common.mustCall((stream) => { | ||
| 34 | + stream.on('error', common.mustCall((err) => { | ||
| 35 | + assert.strictEqual(err, expectedError); | ||
| 36 | + })); | ||
| 37 | + | ||
| 38 | + expectedError = new Error('HTTP/2 server stream error'); | ||
| 39 | + stream.destroy(expectedError); | ||
| 40 | + })); | ||
| 41 | + | ||
| 42 | + server.listen(0, common.mustCall(() => { | ||
| 43 | + const port = server.address().port; | ||
| 44 | + const client = http2.connect(`http://localhost:${port}`); | ||
| 45 | + | ||
| 46 | + const stream = client.request({}); | ||
| 47 | + stream.on('error', common.mustCall((err) => { | ||
| 48 | + assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR'); | ||
| 49 | + | ||
| 50 | + client.close(); | ||
| 51 | + server.close(); | ||
| 52 | + })); | ||
| 53 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments