Skip to content

fix(protocol): keep direct RPC connections alive while awaiting a reply - #883

Open
morningducke wants to merge 5 commits into
scaleapi:mainfrom
morningducke:fix/protocol-rpc-tcp-keepalive
Open

morningducke wants to merge 5 commits into
scaleapi:mainfrom
morningducke:fix/protocol-rpc-tcp-keepalive

Conversation

@morningducke

@morningducke morningducke commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Long-running data-plane RPCs can lose an idle direct TCP connection while the environment prepares its reply. Enable keepalive on the direct connections used by data/add, data/get and data/reset. Where the kernel supports them, probing starts after 30 seconds of inactivity with a 10-second interval and three probes.

Apply each setting to the connected socket. A kernel can expose a setting to Python and still reject it on that socket. The remaining settings and the RPC continue in that case. HTTPX handles proxy routing, bypasses and TLS verification.

Verification

  • Ten of the sixteen direct, proxy, bypass and TLS regression cases failed on main at e4e8151. All sixteen passed with this change on HTTPX 0.27.0 and 0.28.1. A loopback peer received one request when the socket rejected TCP_KEEPINTVL, and observed the connection close.
  • The protocol suite passed 2,107 tests with one skip. Ruff passed.
  • Compared stock and patched native data/add clients against one temporary E2B server. Both short controls succeeded. For the paired long calls the server waited 315 seconds before sending headers and completed both writes. The stock client raised ReadTimeout after 361.461 seconds. The patched client received its result after 315.686 seconds.
  • Gateway shard 5 stopped while pulling nginx:alpine from the Docker mirror with HTTP 429. GitHub requires an upstream repository administrator to rerun that job. Failed gateway job

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issue was found.

Summary

The PR adds best-effort TCP keepalive to direct data-plane RPC connections.

  • Direct data RPC calls keep their TCP connection alive while awaiting a reply.

The previous unnumbered finding is fixed: the three keepalive values now have descriptive class constants.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    RPC["data/add, data/get, data/reset"] --> Client["rpc_client"]
    Client --> Route{"HTTPX route"}
    Route -->|Direct or proxy bypass| Direct["_DirectTransport"]
    Route -->|Proxy| Proxy["AsyncHTTPTransport"]
    Direct --> Socket["Connected TCP socket"]
    Socket --> Settings["Try each keepalive setting"]
    Settings --> Reply["Await reply"]
    Proxy --> Reply
Loading

Reviews (3) · Last reviewed commit: "Merge branch 'main' into fix/protocol-rp..." · Reviewed by Greptile

@morningducke
morningducke marked this pull request as ready for review November 24, 2026 13:39
@morningducke
morningducke requested a review from a team as a code owner November 24, 2026 13:39

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.

1 participant