From 566a694bbc67219d8765921c9b7d494b8a18a50c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 16 Nov 2018 15:51:07 -0800 Subject: [PATCH] http2: replace unreachable error with assertion "That particular `emit('error', ...)` is largely defensively coded and should not ever actually happen." Sounds like an assertion rather than an error event. The code in question has no test coverage because it is believed to be unreachable. Fixes: https://github.com/nodejs/node/issues/20673 PR-URL: https://github.com/nodejs/node/pull/24407 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat --- lib/internal/http2/compat.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 4622d97614a..145e7741049 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -1,5 +1,6 @@ 'use strict'; +const assert = require('assert'); const Stream = require('stream'); const Readable = Stream.Readable; const binding = internalBinding('http2'); @@ -331,15 +332,12 @@ class Http2ServerRequest extends Readable { _read(nread) { const state = this[kState]; - if (!state.closed) { - if (!state.didRead) { - state.didRead = true; - this[kStream].on('data', onStreamData); - } else { - process.nextTick(resumeStream, this[kStream]); - } + assert(!state.closed); + if (!state.didRead) { + state.didRead = true; + this[kStream].on('data', onStreamData); } else { - this.emit('error', new ERR_HTTP2_INVALID_STREAM()); + process.nextTick(resumeStream, this[kStream]); } }