Skip to content

fix(resumablestream): use context.AfterFunc and reject permanent TLS url errors - #44

Open
wssab314 wants to merge 1 commit into
QoderAI:mainfrom
wssab314:fix/resumablestream-goroutine-leak-and-tls-errors
Open

wssab314 wants to merge 1 commit into
QoderAI:mainfrom
wssab314:fix/resumablestream-goroutine-leak-and-tls-errors

Conversation

@wssab314

Copy link
Copy Markdown

Summary

  • Replace the per-stream go s.closeOnContext() watcher goroutine in convention/resumablestream with context.AfterFunc(streamCtx, s.closeOnContext) and deregister it before cancel() on Close(), terminal events, and fail().
  • Classify permanent TLS/certificate (x509.UnknownAuthorityError, x509.HostnameError, x509.CertificateInvalidError, x509.SystemRootsError, x509.ConstraintViolationError, x509.InsecureAlgorithmError, tls.RecordHeaderError) and http.ErrSchemeMismatch errors wrapped in *url.Error as non-retryable while keeping transient *url.Error failures retryable.
  • Add regression tests in convention/resumablestream/resumablestream_test.go and an [Unreleased] changelog entry.

Fixes #43

Why

Previously, constructing a resumable stream with a long-lived context (such as context.Background()) leaked a parked watcher goroutine whenever Close() was omitted, and permanent TLS/scheme errors wrapped in *url.Error retried indefinitely.

Verification

  • make lint (gofmt -l + go vet ./...)
  • make build
  • make test (go test -race -count=1 ./convention/resumablestream/... ./forward/... ./managed/...)
  • make docs-check (local toolchain is Go 1.24; CI checks docs on pinned Go 1.26; no exported API signatures changed)
  • go build ./examples/...
  • Account-backed integration tests not required (offline unit/race fix)

Commands and results:

gofmt -l convention/resumablestream/ -> clean
go vet ./... -> pass
go test -race -count=1 ./convention/resumablestream/... ./forward/... ./managed/... -> PASS
python3 .github/scripts/release_notes.py check -> Changelog is valid

Impact

  • Public API or behavior changed (bugfix: permanent TLS/scheme *url.Error stops retrying)
  • User-facing changes added to CHANGELOG.md under Unreleased
  • Generated API documentation updated (no exported signatures changed)
  • Forward/Managed contract fixtures updated (not applicable)
  • Python and TypeScript parity considered (Go-specific context.AfterFunc and *url.Error classification)
  • Migration notes added for a breaking change (non-breaking)
  • No credentials, .env.live, logs, or generated test output committed

…url errors

Replace the per-stream watcher goroutine in convention/resumablestream with context.AfterFunc so unclosed streams using long-lived contexts do not leak goroutines. Also classify permanent x509/TLS and scheme-mismatch *url.Error failures as non-retryable.

Fixes QoderAI#43
@wssab314
wssab314 requested a review from moonyue-w as a code owner November 24, 2026 05:16

This branch has not been deployed

No deployments
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.

fix(resumablestream): avoid goroutine leak on unclosed streams and stop retrying permanent TLS *url.Error

1 participant