From f866efbbe361dfe4028f6911ec9b9ebff5608329 Mon Sep 17 00:00:00 2001 From: Artem Lavrov Date: Fri, 18 Jun 2021 11:42:11 +0300 Subject: [PATCH] workaround for github.com/nodejs/node/issues/37849 --- src/request-pipeline/destination-request/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/request-pipeline/destination-request/index.ts b/src/request-pipeline/destination-request/index.ts index d065a5b0b..8386b63f5 100644 --- a/src/request-pipeline/destination-request/index.ts +++ b/src/request-pipeline/destination-request/index.ts @@ -49,13 +49,24 @@ export default class DestinationRequest extends EventEmitter implements Destinat this._send(); } + private static _isHttp2ProtocolError (err: Error) { + return err['code'] === 'ERR_HTTP2_STREAM_ERROR' && err.message.includes('NGHTTP2_PROTOCOL_ERROR'); + } + private _sendRealThroughHttp2 (session: ClientHttp2Session) { const reqHeaders = formatRequestHttp2Headers(this.opts); const endStream = !this.opts.body.length; const stream = session.request(reqHeaders, { endStream }); stream.setTimeout(this.timeout, () => this._onTimeout()); - stream.on('error', (err: Error) => this._onError(err)); + stream.on('error', (err: Error) => { + if (DestinationRequest._isHttp2ProtocolError(err)) { + session.destroy(); + this._sendReal(); + } + else + this._onError(err); + }); stream.on('response', headers => { const http2res = createResponseLike(stream, headers);