You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
read_url returns early for an HTTP error, unsupported content type, or an oversized declared response without consuming the body. It clears the request timeout on exit but leaves that body open. A server streaming unsupported content indefinitely therefore keeps its connection after the tool has already returned an error.
Changes
Retain the last response for cleanup and cancel its unlocked body in finally. Cancellation errors do not replace the original tool result; bodies already owned by a reader are left alone.
Add one regression to the existing loopback HTTP fixture. The server sends an unsupported body without ending it; the test checks the existing error result and observes the actual socket closing.
Verification
Windows, Bun 1.3.14, base c2ce3b69fdbb4a691dfd7d39edc2cb8943d85cc1, with the repository's isolated test environment and no real credentials.
The socket regression fails on unmodified main: the tool returns its error, but the connection stays open. It passes after the fix.
bun test sdk/src/__tests__/read-url.test.ts sdk/src/__tests__/read-url-dns-pinning.test.ts: 31 passed / 1 failed before; 32 passed / 0 failed after.
A separate real HTTP probe also observed socketClosed: false before and true after.
Frozen-lockfile install, SDK TypeScript check, SDK build, Windows Freebuff binary build, binary version and official smoke test: passed.
No dependency or public API changes. Existing SSRF checks, DNS pinning, redirect policy, error messages and timeout behavior are preserved. The fixture permits only loopback through the existing injected address policy. No external network or authenticated model/TUI session was used. Linux/macOS, a separate native Node runtime and the full monorepo suite were not run; hosted CI is pending publication.
Good catch and a well-scoped fix. The core change is small and correct: response is hoisted out of the loop so the finally block can see the last response assigned even when the function returns early for an error/unsupported-type/oversized-body case, and then cancels the unlocked body so the underlying socket is released. The guard !response.body.locked correctly avoids double-cancelling a body that's already being streamed/read elsewhere, and .catch(() => {}) avoids a cancellation error masking the original tool result, which is called out explicitly and is good practice.
The added test in read-url-dns-pinning.test.ts is solid: it spins up a loopback server that writes an unsupported content-type and never ends the body, then asserts both the existing error result and that the socket actually closes within a timeout. This gives a concrete regression that fails on main and passes after the patch, which is exactly the kind of evidence this repo wants for a fix like this.
Minor notes for the maintainer porting this by hand:
Confirm this doesn't interact oddly with transports (e.g. undici vs fetch polyfills) where response.body might not support .cancel() identically.
The test lives in the DNS-pinning file rather than a general read-url body-handling test file; a maintainer may want to relocate it, but that's a nit, not a blocker.
Worth double-checking behavior when response is reassigned across redirect hops - only the final response is cancelled, which seems intentional since only the last one is held open.
Overall this is a focused, correctly scoped fix with a real reproducible test. Recommending port-candidate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Why
read_urlreturns early for an HTTP error, unsupported content type, or an oversized declared response without consuming the body. It clears the request timeout on exit but leaves that body open. A server streaming unsupported content indefinitely therefore keeps its connection after the tool has already returned an error.Changes
finally. Cancellation errors do not replace the original tool result; bodies already owned by a reader are left alone.Verification
Windows, Bun 1.3.14, base
c2ce3b69fdbb4a691dfd7d39edc2cb8943d85cc1, with the repository's isolated test environment and no real credentials.bun test sdk/src/__tests__/read-url.test.ts sdk/src/__tests__/read-url-dns-pinning.test.ts: 31 passed / 1 failed before; 32 passed / 0 failed after.socketClosed: falsebefore andtrueafter.git diff --check: passed. ESLint: 0 errors, 5 existing import/resolver warnings.Notes / Scope
No dependency or public API changes. Existing SSRF checks, DNS pinning, redirect policy, error messages and timeout behavior are preserved. The fixture permits only loopback through the existing injected address policy. No external network or authenticated model/TUI session was used. Linux/macOS, a separate native Node runtime and the full monorepo suite were not run; hosted CI is pending publication.