Skip to content

Bun leaves finite iterable REST connections open after Connection: close #2210

Description

@kriszyp

Problem

When Harper runs under Bun 1.3.14, a finite iterable REST response can write its complete body and terminal HTTP chunk without closing the TCP connection, even when the client sent Connection: close.

The Bun HTTP path tries to copy the request's Connection value onto the response. Bun removes that hop-by-hop header from the Request exposed to the fetch handler, however, so Harper never sees the close request. The captured response consequently has no Connection: close header.

Reproduction

Run the stream-error contract under Bun:

npm run build
HARPER_RUNTIME=bun npm run test:integration -- "integrationTests/server/stream-error-contract.test.ts"

The clean and mid-stream iterable REST cases receive the complete JSON body and terminal chunk, then remain open until the test's 15-second client timeout. The same cases close promptly under Node. Bun's SSE and NDJSON cases also close promptly.

Impact

HTTP/1 clients that explicitly request connection closure can remain attached after a finite iterable JSON response. This also makes the Bun integration shard permanently red when the stream-error regression test runs there.

Direction

We need a Bun-supported way to preserve the raw connection-close intent or close that request's socket after the response finishes. Until then, #2070 skips only the two affected Bun iterable REST arms and retains its Bun SSE and NDJSON coverage.

Refs #2070

🤖 Generated by GPT-5 Codex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    P2

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions