Skip to content

fix(http): ensure body resources are released on stream cancellation#3228

Merged
amrbashir merged 3 commits intotauri-apps:v2from
idootop:fix/http-stream-cancellation
Jan 22, 2026
Merged

fix(http): ensure body resources are released on stream cancellation#3228
amrbashir merged 3 commits intotauri-apps:v2from
idootop:fix/http-stream-cancellation

Conversation

@idootop
Copy link
Contributor

@idootop idootop commented Jan 21, 2026

Summary

This PR addresses a resource management issue where HTTP response bodies were not being properly released if the stream was cancelled by the consumer. By implementing the cancel hook in the ReadableStream constructor, we ensure that the internal dropBody() logic is triggered, preventing memory leaks and hanging connections.

Problem

Previously, the implementation only handled AbortSignal events. However, if a user:

  1. Manually called reader.cancel(), or
  2. Exited a for await...of loop early via break or return,
    The ReadableStream would stop, but the underlying resources managed by dropBody() remained active.

Solution

Added the cancel property to the ReadableStream source object to bridge the gap between the Web Stream lifecycle and our internal resource management.

// Ensure cleanup if the consumer cancels the stream
cancel: () => dropBody()

Fixes #3227

@idootop idootop requested a review from a team as a code owner January 21, 2026 14:28
@github-actions
Copy link
Contributor

github-actions bot commented Jan 21, 2026

Package Changes Through 6198c42

There are 8 changes which include updater with minor, updater-js with minor, barcode-scanner with patch, barcode-scanner-js with patch, http with patch, http-js with patch, sql with patch, sql-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.40 2.0.41
api-example-js 2.0.36 2.0.37
barcode-scanner 2.4.3 2.4.4
barcode-scanner-js 2.4.3 2.4.4
http 2.5.6 2.5.7
http-js 2.5.6 2.5.7
sql 2.3.1 2.3.2
sql-js 2.3.1 2.3.2
updater 2.9.0 2.10.0
updater-js 2.9.0 2.10.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I just left one comment to fix the change file.

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@amrbashir amrbashir merged commit 61e9b0a into tauri-apps:v2 Jan 22, 2026
11 checks passed
mrquantumoff pushed a commit to mrquantumoff/plugins-workspace that referenced this pull request Jan 26, 2026
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.

[http] Resource leak: dropBody is not invoked upon stream cancellation

2 participants