Skip to content

fix(platform): do not consume body when inspecting HttpIncomingMessage#6321

Open
xianjianlf2 wants to merge 1 commit into
Effect-TS:v3from
xianjianlf2:fix/http-incoming-message-inspect-locks-body-5341
Open

fix(platform): do not consume body when inspecting HttpIncomingMessage#6321
xianjianlf2 wants to merge 1 commit into
Effect-TS:v3from
xianjianlf2:fix/http-incoming-message-inspect-locks-body-5341

Conversation

@xianjianlf2

Copy link
Copy Markdown

Problem

Logging or toJSON-ing an HttpClientResponse whose body is being streamed locks the underlying ReadableStream, so a later response.stream read fails with TypeError: Invalid state: ReadableStream is locked (#5341).

Root cause

HttpIncomingMessage.inspect() eagerly read the body via Effect.runSync(self.text/self.json). For a one-shot streamed body this consumes and locks the stream. Note that self.text is async, so the runSync call actually always threw and the "body" value was swallowed anyway — the read was a pure destructive side effect.

Fix

Make inspect() side-effect free: it no longer reads the body. An Inspectable.toJSON must not consume a one-shot resource simply by being logged.

Testing

Added a test in packages/platform/test/HttpClient.test.ts ("logging a streamed response does not lock its body") — red before, green after. Full HttpClient.test.ts and tsc -b pass. Changeset included.

Closes #5341

`HttpIncomingMessage.inspect` eagerly read the body via `Effect.runSync`
on `self.text` / `self.json`. For a streamed, one-shot body this invokes
the underlying source read (e.g. `Response.text()`), which locks/consumes
the `ReadableStream`. As a result, merely logging or `toJSON`-ing an
`HttpClientResponse` (or server request) with a streamed body caused
subsequent `response.stream` reads to fail with
`TypeError: Invalid state: ReadableStream is locked`.

Make `inspect` side-effect free by no longer reading the body.

Closes Effect-TS#5341
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7d40c0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/platform Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@IMax153 IMax153 changed the base branch from main to v3 July 13, 2026 23:55
@IMax153 IMax153 added the 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3.

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

Logging HttpClientResponse to console locks the ReadableStream when the response is being streamed

2 participants