Skip to content

fix(http): shared outbound transport; no Client.Timeout for streams - #6300

Closed
xvyimu wants to merge 2 commits into
QuantumNous:mainfrom
xvyimu:pr/b4-outbound-http-client
Closed

xvyimu wants to merge 2 commits into
QuantumNous:mainfrom
xvyimu:pr/b4-outbound-http-client

Conversation

@xvyimu

@xvyimu xvyimu commented Jul 18, 2026 •

Copy link
Copy Markdown

Summary

Fourth small PR from the withdrawn hardening effort: outbound HTTP client lifecycle.

Problem

Applying RELAY_TIMEOUT as http.Client.Timeout covers the entire request including response-body reads, so long-lived streaming completions get aborted mid-body.

Change

  • Introduce common.NewOutboundHTTPTransport with dial / TLS / response-header / idle / expect-continue timeouts
  • Wire relay + OAuth + SSRF-protected fetch to this shared transport
  • Keep http.Client.Timeout = 0 for the general relay client; stall protection is ResponseHeaderTimeout + request context
  • Non-streaming callers that need a wall clock can use GetHttpClientWithTimeout

Env (optional)

RELAY_DIAL_TIMEOUT, RELAY_TLS_HANDSHAKE_TIMEOUT, RELAY_RESPONSE_HEADER_TIMEOUT, RELAY_EXPECT_CONTINUE_TIMEOUT (documented in .env.example).

Test plan

  • go test ./common (outbound transport timeout tests)
  • go test ./service -run 'Http|HTTP|Client|SSRF|Protected|Timeout|Transport|Outbound'
  • Manual: long streaming chat is not cut at RELAY_TIMEOUT wall while hung upstreams still time out on headers

Notes

Summary by CodeRabbit

  • New Features

    • Added more granular, configurable relay timeout settings (dial, TLS handshake, response headers, and expect-continue) and expanded environment examples.
    • Added timeout-scoped HTTP client helpers for both standard and SSRF-protected requests.
    • Improved outbound HTTP connection handling and pooling across direct and proxy modes (including SOCKS variants).
  • Bug Fixes

    • Prevented streaming interruptions from an overly broad global client timeout.
    • Requests now reliably enforce response-header timeouts and honor request cancellation.
  • Documentation

    • Updated guidance explaining how relay timeouts should be used (including streaming-safe recommendations).

…eams

- Add common.NewOutboundHTTPTransport with dial/TLS/response-header timeouts
- Relay/OAuth clients reuse the shared transport
- Keep http.Client.Timeout unbounded so RELAY_TIMEOUT does not cut streaming body reads
- SSRF-protected fetch builds transports via the same helper
@xvyimu xvyimu changed the title fix(http): shared outbound transport fix(http): shared outbound transport; no Client.Timeout for streams Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21fa77b5-92a7-402d-86a7-a3cb68e9e019

📥 Commits

Reviewing files that changed from the base of the PR and between 6450dff and d8b50c6.

📒 Files selected for processing (2)
  • service/protected_fetch_client.go
  • service/protected_fetch_client_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • service/protected_fetch_client.go

Walkthrough

Relay-specific HTTP timeout settings are added, loaded from the environment, and applied through a shared outbound transport factory. OAuth, service, proxy, and protected-fetch clients now reuse this transport while scoped client timeouts remain available for non-streaming requests.

Changes

Outbound HTTP transport

Layer / File(s) Summary
Transport configuration and validation
.env.example, common/constants.go, common/init.go, common/http_client.go, common/http_client_test.go
Adds relay timeout settings, centralized transport construction, and tests for lifecycle timeouts, response-header timeouts, and request cancellation.
Outbound client integration
oauth/http_client.go, service/http_client.go
Uses shared transports for OAuth, general, SSRF-protected, HTTP proxy, and SOCKS proxy clients, with optional per-client timeouts.
Protected fetch transport integration
service/protected_fetch_client.go, service/protected_fetch_client_test.go
Uses the configured relay dial timeout and shared transport factory, and verifies that protected-fetch client timeouts remain unbounded.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant ServiceHTTPClient
  participant NewOutboundHTTPTransport
  participant ProxyOrDialer
  participant RemoteHTTPServer
  Application->>ServiceHTTPClient: initialize outbound client
  ServiceHTTPClient->>NewOutboundHTTPTransport: provide proxy or dial function
  NewOutboundHTTPTransport->>ProxyOrDialer: configure connection dialing
  ProxyOrDialer-->>NewOutboundHTTPTransport: return configured transport
  ServiceHTTPClient->>RemoteHTTPServer: send request with transport timeouts
  RemoteHTTPServer-->>ServiceHTTPClient: response headers or timeout
Loading

Possibly related PRs

Suggested reviewers: calcium-ion

Poem

I’m a rabbit with a timeout tune,
Dialing beneath the silver moon.
Headers wait, then streams run free,
SOCKS hops softly through the tree.
Shared transports hum just right—
Hop, hop, shipped by morning light!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the shared outbound transport refactor and the shift away from Client.Timeout for streaming requests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/protected_fetch_client.go`:
- Line 72: Remove the client.Timeout assignment from
newProtectedFetchHTTPClientWithProxy, while preserving the RelayDialTimeout
setting on its transport dialer. Ensure this proxy client leaves response body
reads unbounded, matching the standard outbound HTTP client behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 667b24a7-4e28-4d07-8847-90f8e2533a72

📥 Commits

Reviewing files that changed from the base of the PR and between 5a6c53d and 6450dff.

📒 Files selected for processing (8)
  • .env.example
  • common/constants.go
  • common/http_client.go
  • common/http_client_test.go
  • common/init.go
  • oauth/http_client.go
  • service/http_client.go
  • service/protected_fetch_client.go

Comment thread service/protected_fetch_client.go Resolved
CodeRabbit #6300: newProtectedFetchHTTPClientWithProxy still applied
RELAY_TIMEOUT to http.Client.Timeout, which covers response-body reads
and aborts long-lived streams. Match newOutboundHTTPClient: dial timeout
only; leave client.Timeout at 0.
@xvyimu

xvyimu commented Jul 19, 2026

Copy link
Copy Markdown
Author

Addressed CodeRabbit review:

  • Removed http.Client.Timeout = RELAY_TIMEOUT from newProtectedFetchHTTPClientWithProxy.
  • Dial timeout remains on the dialer; client.Timeout stays 0 so streaming body reads are not cut mid-stream (matches newOutboundHTTPClient).
  • Added TestProtectedFetchHTTPClientTimeoutUnbounded.

Pushed: d8b50c68 on pr/b4-outbound-http-client.

@xvyimu

xvyimu commented Jul 23, 2026

Copy link
Copy Markdown
Author

Withdrawing this contribution. No further action needed from maintainers. Closing and deleting the head branch.

@xvyimu xvyimu closed this Jul 23, 2026
@xvyimu
xvyimu deleted the pr/b4-outbound-http-client branch July 23, 2026 05:44
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.

2 participants