Skip to content

[core] gcs_server retains dead gRPC connections indefinitely when middlebox forwarding state expires (fd exhaustion) #68785

Backlog

Description

@summaryzb

What happened + What you expected to happen

[core] gcs_server retains dead gRPC connections indefinitely when middlebox forwarding state expires (fd exhaustion)

What happened

On a production Kubernetes cluster with kube-proxy in IPVS mode, gcs_server monotonically accumulates ESTABLISHED TCP connections whose clients are long gone, until the process exhausts its file descriptor limit and starts failing with Too many open files. The dead
connections are never reclaimed by the server — we observed sockets idle for ~29 hours — and only a gcs_server restart releases them.

The mechanism, end to end:

  1. Clients reach GCS through a Kubernetes Service (ClusterIP). kube-proxy in IPVS mode NATs the connection to the head pod. The IPVS forwarding entry for an established TCP connection expires after 900 s of inactivity by default (15*60*HZ in
    net/netfilter/ipvs/ip_vs_proto_tcp.c).
  2. If no packet flows for more than 900 s — entirely possible for an idle gRPC channel — the IPVS entry is gone while both endpoints still consider the connection ESTABLISHED.
  3. When the client later closes the connection (or the client pod is rescheduled/restarted), its FIN/RST is routed to the ClusterIP, matches no IPVS state, and never reaches gcs_server.
  4. From then on the server holds a fully dead socket indefinitely: there is no RPC traffic, no gRPC keepalive ping, and no kernel TCP keepalive probe on such a connection (see Root cause), so nothing ever touches the socket and the fd is never freed.

Kubernetes treats this middlebox behavior as working-as-intended: kubernetes/kubernetes#104098 was closed on those grounds (kube-proxy only cleans up UDP conntrack entries, and deleting a conntrack entry cannot
inject an RST into either endpoint). The IPVS timeout was later made configurable via --ipvs-tcp-timeout (kubernetes/kubernetes#83208, #85517), but any finite
middlebox idle timeout that is shorter than the endpoint's probing interval reproduces this class of bug — the endpoint application has to bound connection lifetime itself.

Environment

  • Ray 2.53.0 (where we hit this): gcs_server is a C++ gRPC server built against Ray's vendored gRPC v1.57.1 (bazel/ray_deps_setup.bzl).
  • Current master is affected too: master vendors gRPC v1.69.0 (bazel/ray_deps_setup.bzl), and
    GrpcServer::Run() still hardcodes GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS = 0 and never sets any GRPC_ARG_MAX_CONNECTION_* argument. No fix is merged upstream as of this writing
    (2026-12).
  • Kubernetes, kube-proxy in IPVS mode (default IPVS established-TCP timeout: 900 s).
  • Symptoms appear after days of uptime on a busy cluster; fd usage grows monotonically and never decreases.

Root cause

A chain of mismatched defaults leaves idle server-side connections with zero probing at every layer:

Layer Default probe / timeout Effective for an idle connection?
kube-proxy IPVS forwarding state 900 s idle timeout (kernel source) — (this is the middlebox that expires)
Linux kernel TCP keepalive (tcp_keepalive_time) 7200 s (tcp(7)) No — gRPC never sets SO_KEEPALIVE on accepted sockets (verified by reading Ray's vendored gRPC v1.57.1 sources), so the kernel never probes
gRPC server GRPC_ARG_KEEPALIVE_TIME_MS 2 h in gRPC (keepalive doc); Ray overrides to 10 s via grpc_keepalive_time_ms No — Ray hardcodes GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS = 0 in GrpcServer::Run() (present on master), so the server pings only while an RPC is outstanding (per the gRPC keepalive doc)
gRPC server max connection idle / age infinite (gRPC default, gRFC A9) No — Ray never sets GRPC_ARG_MAX_CONNECTION_IDLE_MS / GRPC_ARG_MAX_CONNECTION_AGE_MS

So for a connection with no in-flight RPCs:

  1. The middlebox state expires first (900 s in our setup).
  2. The client's eventual FIN/RST is lost at the expired middlebox.
  3. Every server-side detection mechanism that could notice the dead peer is disabled: no outstanding RPC means no gRPC ping (hardcoded PERMIT_WITHOUT_CALLS = 0), no kernel probe (no SO_KEEPALIVE), and no idle/age bound (gRPC defaults to infinite and Ray doesn't
    override it).

All failure detection in this stack is driven by traffic or probing; for an idle connection there is neither. The socket stays ESTABLISHED forever from the server's point of view.

This is exactly the failure mode gRFC A8 motivates for client-side keepalive: middleboxes silently drop idle connections (the gRFC cites GCP load balancers killing idle connections after 10
minutes and AWS ELB after 60 seconds; IPVS at 900 s is the same class of middlebox). Client-side keepalive alone cannot fix the server here — it only keeps the middlebox state fresh while the client is alive; once the client's close packet is lost, only the server can
reclaim its own fd.

Evidence

  • gcs_server fd count grows monotonically over days and the process eventually logs Too many open files (accept fails; new RPCs to GCS fail). Restarting gcs_server immediately drops the fd count back to normal.
  • Inspecting the process's sockets (ss -tia / TCP_INFO) shows a large fraction of ESTABLISHED connections to one SNAT'd peer address whose lastsnd/lastrcv/lastack ages are far beyond 900 s, the oldest ~29 h — connections whose IPVS forwarding state (900 s)
    expired long ago and on which no byte has flowed in either direction for many hours.
  • The peer addresses of those sockets belong to client pods that no longer exist (restarted/rescheduled long before); their close packets never reached the head node, consistent with the mechanism above.

Related

Proposed fix

Make the server-side connection lifecycle configurable in Ray, default-off (zero behavior change unless explicitly enabled). We have a complete implementation ready on a master-based branch (gcs-fd-leak, commit f11d46098c, on top of master da26a34de6),
touching three files:

1. Four new RAY_CONFIG items in src/ray/common/ray_config_def.h (verbatim from the branch):

RAY_CONFIG(int64_t, grpc_server_max_connection_age_grace_ms, -1)

2. Wiring in GrpcServer::Run() in src/ray/rpc/grpc_server.cc: the hardcoded GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 0 becomes a read of grpc_server_keepalive_permit_without_calls (default false → the same 0 as today), and each
GRPC_ARG_MAX_CONNECTION_IDLE_MS / GRPC_ARG_MAX_CONNECTION_AGE_MS / GRPC_ARG_MAX_CONNECTION_AGE_GRACE_MS channel arg is injected only when its config is >= 0. The -1 defaults therefore preserve gRPC's current infinite defaults exactly, and out-of-the-box
behavior is byte-for-byte identical to before. Since GrpcServer is shared by gcs_server, the raylet, and core workers, one change covers all Ray-internal gRPC servers. As with all RAY_CONFIG items, values can also be set via environment variables (e.g.
RAY_grpc_server_max_connection_idle_ms=300000).

3. Two new unit tests in src/ray/rpc/tests/grpc_server_client_test.cc:

  • TestIdleConnectionNotClosedWithDefaultConfigs — asserts all four configs are at their disabled defaults and that the server does not close an idle connection (rollback-safety: default behavior is unchanged).
  • TestGrpcServerMaxConnectionIdleFixture.TestServerClosesIdleConnection — starts the server with grpc_server_max_connection_idle_ms=1000, verifies the client channel leaves READY within 10 s (server-sent GOAWAY), and that a subsequent RPC reconnects transparently
    and succeeds.

Full suite result: 9/9 tests PASSED locally (bazel test //src/ray/rpc/tests:grpc_server_client_test, 54.3 s). We also ran a RED check against the unpatched base: TestServerClosesIdleConnection fails without the grpc_server.cc change, confirming the test
actually exercises the new channel arg.

Why these four knobs (semantics per gRFC A9):

  • max_connection_idle_ms — the direct fix: the server sends GOAWAY and closes any connection that has had no outstanding RPCs for this long. The fd is reclaimed on the server's own timer, without depending on any client packet surviving the middlebox.
  • keepalive_permit_without_calls=true — lets the existing 10 s server keepalive also run on idle connections, which both keeps the middlebox forwarding state fresh and lets the server detect dead peers via the keepalive timeout.
  • max_connection_age_ms / max_connection_age_grace_ms — bound the total connection lifetime and provide a bounded fd-release guarantee even for connections pinned open by hung streaming/long-poll RPCs.

Keeping the defaults disabled preserves current behavior for everyone else; operators behind stateful middleboxes can opt in. Example for IPVS clusters (any value comfortably below the middlebox timeout works):

RAY_grpc_server_keepalive_permit_without_calls=true
RAY_grpc_server_max_connection_idle_ms=300000   # 5 min < 900 s IPVS timeout

Workarounds (for anyone hitting this today)

  • LD_PRELOAD shim: wrap accept4() to set SO_KEEPALIVE plus TCP_KEEPIDLE below the middlebox timeout (e.g. 600 s < 900 s) on every accepted socket. gRPC accepts connections via glibc accept4, so a ~30-line interposer injected into the head pod works around
    the issue without rebuilding Ray: kernel keepalive probes both refresh the IPVS entry and eventually detect dead peers.
  • Raise the fd limit (nofile ulimit): only buys capacity — the leak is unbounded, so this delays but does not prevent exhaustion.
  • Client-side gRPC keepalive options keep the middlebox state fresh only while the client process is alive; they cannot reclaim server fds once a client's FIN/RST is lost.

Offer to contribute

The implementation described above is ready on a master-based branch (commit f11d46098c): config-only, default-off, with unit tests passing locally (9/9, including a default-behavior regression test and a RED check against the unpatched base). We are happy to open a
PR as-is or rework it based on maintainer feedback. In particular, we'd appreciate guidance on:

  1. Config naming — are grpc_server_keepalive_permit_without_calls / grpc_server_max_connection_{idle,age,age_grace}_ms acceptable, or would you prefer a different prefix?
  2. Defaults — keep everything default-off (our preference, zero behavior change), or should Kubernetes/Helm deployments ship with an enabled-by-default idle timeout?

Versions / Dependencies

All versions in k8s nonhost network env

Reproduction script

Kubernetes treats this middlebox behavior as working-as-intended: kubernetes/kubernetes#104098 was closed on those grounds (kube-proxy only cleans up UDP conntrack entries, and deleting a conntrack entry cannot
inject an RST into either endpoint). The IPVS timeout was later made configurable via --ipvs-tcp-timeout (kubernetes/kubernetes#83208, #85517), but any finite
middlebox idle timeout that is shorter than the endpoint's probing interval reproduces this class of bug — the endpoint application has to bound connection lifetime itself.

Issue Severity

No response

Activity

  1. added
    bug
    triage
    on Dec 3, 2026
  2. changed the title [-][<Ray component: Core|RLlib|etc...>][/-] [+][core] gcs_server retains dead gRPC connections indefinitely when middlebox forwarding state expires (fd exhaustion)[/+] on Dec 3, 2026
  3. added
    core
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommunity-backlogcorestabilitytriage

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions