Skip to content

Cancel unread response streams instead of draining them - #3085

Merged
adamw merged 2 commits into
masterfrom
fix-sttp-issue-3084-c244adcf
Nov 26, 2026
Merged

adamw merged 2 commits into
masterfrom
fix-sttp-issue-3084-c244adcf

Conversation

@adamw

@adamw adamw commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #3084

With asStream/asStreamAlways, the body was drained after the user's function finished. On a body that never ends (e.g. SSE), draining never completes, so:

  • cancelling a request before the stream was read hung,
  • a function that returned without reading the stream hung.

Now the unread body is cancelled instead. If the body was already read, this does nothing. If not, the connection is closed (on HTTP/1.1 it can't be reused with an unread body anyway).

Changed backends:

  • HttpClient (fs2, fs2-ce2, zio, zio1, monix): cancel the body's Publisher
  • Pekko / Akka: cancel the entity stream instead of discardEntityBytes

The same applies to cleanup when a WebSocket was expected but a regular response arrived.

Added two shared streaming tests that cover both cases.

🤖 Generated with Claude Code

Draining never completes for a never-ending body (e.g. SSE), which hung
both cancellation and normal completion of asStream requests.

Fixes #3084
@adamw
adamw merged commit 3ecb9d7 into master Nov 26, 2026
64 of 71 checks passed
@adamw
adamw deleted the fix-sttp-issue-3084-c244adcf branch November 26, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpClientBackend can hang when using asStreamAlways

1 participant