Skip to content

sdk/shreds: bound RPC client request timeout and connection pool#3974

Open
nikw9944 wants to merge 1 commit into
mainfrom
fix/shreds-rpc-timeout
Open

sdk/shreds: bound RPC client request timeout and connection pool#3974
nikw9944 wants to merge 1 commit into
mainfrom
fix/shreds-rpc-timeout

Conversation

@nikw9944

@nikw9944 nikw9944 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Configure the shreds SDK RPC client with a bounded 15s per-request timeout and a sized connection pool (128) instead of wrapping the unbounded, lightly-pooled http.DefaultClient.

This is the SDK-level counterpart to the internet-latency-collector hardening (#3973). http.DefaultClient has no request timeout and keeps only 2 idle connections per host, so against a slow or degraded ledger RPC endpoint a request can block indefinitely — long enough for a transaction's recent blockhash to expire before it is sent, which surfaces as BlockhashNotFound at preflight. A bounded timeout makes requests fail fast so the caller can retry with a fresh blockhash. The existing transient-error retry wrapper is unchanged.

Diff Breakdown

Category Files Lines (+/-) Net
Scaffolding 1 +34 / -3 +31
Tests 1 +43 / -0 +43
Docs 1 +2 / -0 +2
Total 3 +79 / -3 +76

Small change: RPC-client construction hardening plus a test; no logic/algorithm changes.

Key files (click to expand)
  • sdk/shreds/go/rpc.go — add newHTTPClient (bounded timeout + sized transport) and use it for the RPC client's inner HTTP client instead of http.DefaultClient.
  • sdk/shreds/go/rpc_test.go — new tests asserting the client has a bounded timeout and that a slow request is aborted near the timeout rather than hanging.

Testing Verification

  • TestNewHTTPClient_HasBoundedTimeout: the constructed client has a non-zero timeout and a connection pool sized to defaultMaxConns (guards against regressing back to http.DefaultClient).
  • TestNewHTTPClient_TimesOutSlowRequest: a request to a handler that sleeps 3s is aborted within ~200ms, confirming requests are bounded.

Note

The identical unbounded-http.DefaultClient pattern exists in sdk/revdist/go/rpc.go; left out of this PR to keep it focused, but worth a follow-up.

The shreds SDK RPC client wrapped http.DefaultClient, which has no request
timeout and keeps only 2 idle connections per host. Against a slow or degraded
ledger RPC endpoint a request can block indefinitely, long enough for a
transaction's recent blockhash to expire before it is sent, surfacing as
BlockhashNotFound. Configure the underlying http.Client with a bounded 15s
per-request timeout and a connection pool sized for concurrent use so requests
fail fast and the caller can retry with a fresh blockhash.
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