Skip to content

carrier/exit: bound and pre-size relay body reads#138

Merged
Kianmhz merged 1 commit into
Kianmhz:mainfrom
poulcarlsen53:bounded-body-reads
May 20, 2026
Merged

carrier/exit: bound and pre-size relay body reads#138
Kianmhz merged 1 commit into
Kianmhz:mainfrom
poulcarlsen53:bounded-body-reads

Conversation

@poulcarlsen53
Copy link
Copy Markdown
Contributor

Summary

  • add bounded body readers for carrier relay responses and exit /tunnel requests
  • preallocate exactly when Content-Length is known
  • use a LimitedReader fallback when length is unknown so oversized bodies are rejected without reading unbounded data
  • return HTTP 413 for oversized /tunnel request bodies

Why

This reduces avoidable large intermediate allocations on normal relay bodies and protects both sides from unexpectedly huge HTML/error/request payloads.

Verification

  • go test -count=1 ./internal/carrier -run TestReadRelayResponseBodyBoundsAndPreallocates
  • go test -count=1 ./internal/exit -run TestReadTunnelRequestBodyBoundsAndPreallocates
  • go test -count=1 ./...
  • go vet ./...

@Kianmhz Kianmhz merged commit 530a801 into Kianmhz:main May 20, 2026
6 checks passed
Kianmhz pushed a commit that referenced this pull request May 20, 2026
Classify dial errors from http.Client.Do separately from relay/server
failures and route them through a short 15s local-offline blacklist
instead of the 30m/1h endpoint penalty tiers. A quota-free TCP probe
to google_host:443 clears those transient backoffs when the network
returns, so airplane-mode / captive-portal / brief blackout recovery
happens in seconds rather than minutes.

Drops Linux-only syscall.ENONET from the errno set so the carrier builds
on macOS/Windows; ENONET ("machine is not on the network") is already
covered by the message-substring fallback in isLocalNetworkOffline.

The HTTP 500 mock in TestPollOnceMarksOnlyDoErrors... now sets
ContentLength: -1 so the post-#138 readRelayResponseBody treats the
body as unknown-length and reads it through (rather than honoring
the zero-valued ContentLength as "empty body").

Co-authored-by: poulcarlsen53 <poulcarlsen53@gmail.com>
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.

3 participants