Skip to content

[Bug]: Settle SOCKS5 streaming uploads on cancellation and early final responses #5110

Closed

Description

@lidge-jun

Client or integration

Direct HTTP/API client

Area

Proxy and routing

Summary

The upload loop awaits the caller body reader before parsing any response head. Aborting destroys the socket but does not settle a pending bodyReader.read(). A stalled upload can therefore keep the fetch promise pending, including when the peer has already returned a final response.

Reproduction

Static source trace at 7864869c31c41cca9830d93540238f17df8faafb; the following fake-upstream regression is the proposed executable reproduction, not a claimed local test result.

  1. Use a fake SOCKS peer and a Request body stream that produces one chunk and then leaves its next read pending.
  2. Abort after the headers/chunk arrive, or have the upstream send a final response without waiting for the upload to finish.
  3. Assert bounded settlement, request-body cancellation, no further upload writes and no orphaned socket/listeners. Do not use a production endpoint.

Version

7864869

Operating system

Source review on macOS 27.0; the transport logic is cross-platform. Runtime reproduction has not been executed in this analysis.

Provider and model

Not provider- or model-specific. Use a local fake upstream and no real credentials.

Logs or error output

No live traffic or runtime logs collected. Evidence is the exact source path below.

Screenshots and supporting files

src/lib/socks5-fetch.ts:559; src/lib/socks5-fetch.ts:573; src/lib/socks5-fetch.ts:589. Existing handshake/response abort support is retained; this is a request-body lifecycle gap, not a claim that cancellation is absent. Related #2894.

Redacted configuration

Use a test-owned loopback upstream and SOCKS tunnel or the pinned direct helper as specified above. No user home, provider credentials or running proxy is needed.

Implementation path

  1. MODIFY src/lib/socks5-fetch.ts: observe the final response head concurrently with upload, skipping informational responses.
  2. Race body reads/drain waits with caller abort and early final response. On termination, cancel/release the body reader without allowing a hanging cancel callback to block settlement.
  3. Preserve the first terminal cause and caller abort reason; do not send a terminating chunk after an early final response. Avoid concurrent consumers of the same socket reader.
  4. ADD focused tests/lib/socks5-upload-lifecycle.test.ts regressions.

Acceptance criteria and verification

  • Pending body read + caller abort rejects with the original reason and releases resources.
  • Early final response resolves and stops upload.
  • Socket error/timeout during a stalled body read settles rather than hanging.
  • Backpressure, normal POST completion and informational response handling remain correct.

New test files must be registered in scripts/test-layout/layout.json and tests/fixtures/test-layout-expected.json; split tests rather than raise file-size caps. Update structure/transports/inventory.md and any other owner declared by the manifest. Run focused regressions and exact-head hosted CI in the implementation PR; no passing runtime result is claimed here.

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    on Sep 19, 2026
  2. added
    proxy
    on Sep 19, 2026
  3. lidge-jun commented on Sep 19, 2026

    @lidge-jun
    OwnerAuthor

    Resolved on dev by #5127, merge commit 9824aa55bb0ed5fb27ca92ed0851a2fd5529123c.

    The upload and final response are observed concurrently with one socket reader. Stalled uploads settle on caller cancellation or peer response/failure; normal chunked completion remains covered. Regressions activate cancellation only after the upstream receives body bytes and verify Error/string/null/object reasons, early 413, peer disappearance and ordinary POST. Exact head cc8eeab585a7ce175cecf73268a325497c26eaf4 passed all applicable hosted checks and aggregate ci: https://github.com/lidge-jun/opencodex/actions/runs/35432240251. Linux and macOS logs explicitly show the new cases passing.

    Independent review findings were resolved, current dev integration was inspected to preserve the prior null-body fix, and merged state plus dev tip were reread before closure. Local tests/typecheck/build/install were NOT RUN. The cumulative dev run remains monitored separately.

  4. lidge-jun commented on Sep 19, 2026

    @lidge-jun
    OwnerAuthor

    Final acceptance audit found missing direct activation evidence for two original criteria: informational response handling before the final response, and timeout settlement while an upload body read is stalled. Reopening for focused real-transport regressions and hosted proof, preserving deadlines and existing assertions. Existing implementation/CI evidence remains recorded; no new production failure is asserted. Re-closure will follow the verified regression follow-up landing.

  5. lidge-jun commented on Sep 20, 2026

    @lidge-jun
    OwnerAuthor

    Original acceptance verification is now complete. Follow-up #5225 landed on dev as3f9fe3fa2993126c95a0c64627f4a5d609e0a1a7; ancestry and the reviewed tree are verified. Exact-head run35477114410 passed, and macOS log105988178063 directly shows the informational100/103→continued upload→final200 case and the real timeout callback during a stalled read passing, including resource cleanup. Original #5127 coverage remains intact. No production behavior, deadline or assertion was weakened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproxy

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions