From d42cff57ee0c20bfbef2f279186bdcc235a2e348 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Tue, 3 Sep 2024 17:07:58 +0200 Subject: [PATCH] Fix Node.js v16 error responses on HTTP1.1 (#1206) Signed-off-by: Timo Stamm --- .github/workflows/conformance-express.yaml | 2 +- .github/workflows/conformance-fastify.yaml | 2 +- .github/workflows/conformance-node.yaml | 2 +- packages/connect-node/src/node-universal-handler.ts | 11 ++++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/conformance-express.yaml b/.github/workflows/conformance-express.yaml index 77533b0b0..ac331b543 100644 --- a/.github/workflows/conformance-express.yaml +++ b/.github/workflows/conformance-express.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [21.1.0, 20.9.0, 18.16.0] + node-version: [21.1.0, 20.9.0, 18.16.0, 16.20.0] name: "Node.js ${{ matrix.node-version }}" timeout-minutes: 10 steps: diff --git a/.github/workflows/conformance-fastify.yaml b/.github/workflows/conformance-fastify.yaml index cd903cb56..94e175429 100644 --- a/.github/workflows/conformance-fastify.yaml +++ b/.github/workflows/conformance-fastify.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [21.1.0, 20.9.0, 18.16.0] + node-version: [21.1.0, 20.9.0, 18.16.0, 16.20.0] name: "Node.js ${{ matrix.node-version }}" timeout-minutes: 10 steps: diff --git a/.github/workflows/conformance-node.yaml b/.github/workflows/conformance-node.yaml index bcec39217..110c6e5ca 100644 --- a/.github/workflows/conformance-node.yaml +++ b/.github/workflows/conformance-node.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [21.1.0, 20.9.0, 18.16.0] + node-version: [21.1.0, 20.9.0, 18.16.0, 16.20.0] side: [client, server] name: "Node.js ${{ matrix.node-version }} ${{ matrix.side }}" timeout-minutes: 10 diff --git a/packages/connect-node/src/node-universal-handler.ts b/packages/connect-node/src/node-universal-handler.ts index 2eb7230d4..15d9e027e 100644 --- a/packages/connect-node/src/node-universal-handler.ts +++ b/packages/connect-node/src/node-universal-handler.ts @@ -207,7 +207,16 @@ export async function universalResponseToNodeResponse( async function* asyncIterableFromNodeServerRequest( request: NodeServerRequest, ): AsyncIterable { - for await (const chunk of request) { + const it = request.iterator({ + // Node.js v16 closes request and response when this option isn't disabled. + // When one of our handlers receives invalid data (such as an unexpected + // compression flag in a streaming request), we're unable to write the error + // response. + // Later major versions have a more sensible behavior - we can revert this + // workaround once we stop supporting v16. + destroyOnReturn: false, + }); + for await (const chunk of it) { yield chunk; } }