Repository navigation
feat(sandbox-relay): configurable keepalive times, and a dead-peer test - #866
Conversation
…dead peer is dropped The relay already pings every connection (20 s, 10 s timeout), but nothing showed that this tears down an Attach whose host vanished without a TCP close, nor that the servers accept the workers' own client pings. - MOCA_RELAY_KEEPALIVE_TIME_MS and MOCA_RELAY_KEEPALIVE_TIMEOUT_MS set the two times; unset or empty is the default, anything but a positive integer below 2^31-1 refuses the boot. Documented in the configuration reference. - keepalive-dead-peer.transport.test.ts freezes a worker's connection (every byte swallowed, no FIN or RST): the relay tears it down, removes presence and admits the same id again within keepalive time + timeout. With keepalive off the frozen session is still held and the reconnect refused. A client pinging every 100 ms stays READY: grpc-js's server has no ping-rate policy, so the workers' 30 s pings never draw GOAWAY too_many_pings. Closes rossoctl#439 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
- The worker-pings test ran with the relay's keepalive on, so the client's acks of the relay's PINGs alone could meet its write count. The relay's keepalive is off there now: every client->relay write is a client PING (and with the client's pings disabled the test fails, 0 writes). - The comment and the docs row said the PINGs cross ghostunnel inside the TLS stream. ghostunnel terminates TLS; it is an L4 TLS proxy that forwards the bytes without parsing HTTP/2, so it answers no PING and the worker acks the relay's PINGs itself. The passthrough Route forwards TLS bytes. - MOCA_RELAY_KEEPALIVE_TIME_MS / _TIMEOUT_MS now refuse values below 1000, so `20` meant as seconds no longer pings every 20 ms. The error names the variable and the unit. startRelay's explicit keepalive option is not bound by the floor; the env-wiring test uses 1000. Refs rossoctl#439 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review at 5a53d05
Adds MOCA_RELAY_KEEPALIVE_TIME_MS / _TIMEOUT_MS (validated integer ms in [1000, 2^31-1), boot refusal otherwise), reads them in startRelay before anything binds or touches Redis, and adds a dead-peer transport test plus a no-too_many_pings test. Verified against grpc-js 1.14.7 (the lockfile version): KEEPALIVE_MAX_TIME_MS = ~(1 << 31) is the server's "off" value, grpc.keepalive_permit_without_calls is read only on the client transport, and there is no server ping-rate policy, so the comment's claims hold. The worker's 30 s/10 s client keepalive (dial.go), the duplicate-id refusal in relay.ts, and the 5m Route timeout also match the comments and docs. The validation regex rejects the octal, hex, exponent and fractional forms the tests list.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (sandbox-relay src + tests), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: all checks passing at submit time
Body-only nit: deploy/vm/env/relay.env.example lists the relay's optional knobs as commented lines (e.g. #SH_SANDBOX_MAX_INFLIGHT=2). Consider adding #MOCA_RELAY_KEEPALIVE_TIME_MS=20000 and #MOCA_RELAY_KEEPALIVE_TIMEOUT_MS=10000 there so VM operators can find them.
Drafted by an AI reviewer and approved by a human before posting.
| /** | ||
| * MOCA_RELAY_KEEPALIVE_TIME_MS and MOCA_RELAY_KEEPALIVE_TIMEOUT_MS: unset or empty is the default | ||
| * (RELAY_KEEPALIVE), anything else must be an integer of milliseconds from MIN_KEEPALIVE_MS up, or | ||
| * the relay does not boot. Keepalive |
There was a problem hiding this comment.
nit: This docstring has a stray line break (Keepalive / cannot be turned off here), and it says "from MIN_KEEPALIVE_MS up" without the upper bound keepaliveMs enforces (below MAX_TIMER_MS, 2^31-1, which grpc-js reads as keepalive off). Suggest reflowing to e.g. "...must be an integer of milliseconds from MIN_KEEPALIVE_MS up to below MAX_TIMER_MS, or the relay does not boot. Keepalive cannot be turned off here: ..."
There was a problem hiding this comment.
Done in c28395e: reflowed, and it now gives the upper bound ("from MIN_KEEPALIVE_MS up to below MAX_TIMER_MS (which grpc-js reads as keepalive off)"). The body nit is in the same commit: relay.env.example lists both knobs as commented lines with their defaults and bounds, and since env-parity reads commented lines too, both are in its NOT_ENV_ON_K8S with the reason.
…he upper bound Review follow-up. relay.env.example lists the relay's optional knobs as commented lines, so VM operators find MOCA_RELAY_KEEPALIVE_TIME_MS and _TIMEOUT_MS there too, with their defaults and bounds. env-parity reads commented lines as well, so both are listed in its NOT_ENV_ON_K8S with their reason (a code default; no manifest sets them). relayKeepalive's docstring now gives the upper bound keepaliveMs enforces, on one line. Refs rossoctl#439 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Brings 25 upstream merges since 1aa8dd6, among them the sbx OIDC identity provider (rossoctl#851), the Redis schema-version key and config bundle format marker (rossoctl#868), the provisioner Redis ACL user (rossoctl#869), the relay keepalive env (rossoctl#866), the per-source OIDC pending bound with the forwarded-headers Route pin (rossoctl#874), the egress refusal hints and control-plane index (rossoctl#864), the empty-workspace sweep (rossoctl#872) and the orphan-sweep log split (rossoctl#849). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #439
Where main stands on each point of the issue
newServer(): DONE on main, before this PR.relayServerOptions()inpackages/sandbox-relay/src/main.tssetsgrpc.keepalive_time_ms20 s andgrpc.keepalive_timeout_ms10 s on both listeners (SBX0 §3.4), so a dead peer is already dropped in at most 30 s.grpc.http2.min_ping_interval_without_data_ms, and readsgrpc.keepalive_permit_without_callsonly on a client. It has no server-side ping-rate policy, so it never sends GOAWAYtoo_many_pings, and setting those options on the relay would do nothing.What changed and why
relayKeepalive(env)readsMOCA_RELAY_KEEPALIVE_TIME_MSandMOCA_RELAY_KEEPALIVE_TIMEOUT_MS. Unset or empty keeps the default (20000 / 10000). Anything else must be an integer of milliseconds from 1000 up to below 2147483647, or the relay refuses to boot. This followsSH_SANDBOX_MAX_INFLIGHT: the error names the variable, never the value. The floor refuses a value meant as seconds (20would ping every 20 ms), and its error names the unit. The upper bound matters because grpc-js treats 2^31-1 as "keepalive off", and Node timers overflow above it. Keepalive cannot be turned off this way. The explicitkeepaliveoption ofstartRelayis not bound by the floor; that is how the tests use smaller values.startRelayreads the variables first, so a bad value fails the boot before anything binds or touches Redis. An explicitkeepaliveoption still overrides the env.20, meant as seconds) or otherwise malformed refuses the relay's boot, naming the variable and the unit. Unset keeps today's 20 s / 10 s, so a deployment that sets neither is unaffected.main.tsnow gives both reasons for keepalive (silent Execs behind idle-closing load balancers, and dead P4 hosts), and records the grpc-js ping-policy facts above.docs/reference/configuration.md: two new rows in the Sandbox relay table.Tests
New file
packages/sandbox-relay/test/keepalive-dead-peer.transport.test.ts. It uses real grpc-js transports and a TCP proxy whosefreeze()drops every byte in both directions while keeping the sockets open (no FIN or RST). From the relay, that looks like a host whose network dropped.removeruns, and the samesandboxIdattaches again.removewas never called, and a reconnect with the same id is refused (no second presenceput). This is the issue's symptom.keepalive_permit_without_callsstays READY for 2 s, and its Attach stream does not error. This is 300 times the rate of the Go worker. The relay's own keepalive is off in this test, so it sends no PING for the client to ack. Every client-to-relay write the proxy counts in the idle window is therefore the client's own PING; at least 5 are required. With the client's pings disabled, the test fails with 0 writes. If a later grpc-js starts enforcing a ping rate, this test fails.Added to
packages/sandbox-relay/test/keepalive.transport.test.ts:relayKeepalivedefaults, overrides and whitespace handling.0,-1,1.5,1e4,20s,0x10,012,offand2147483647for each variable.1,20and999as below the 1 s floor, with an error that names the variable and the unit.1000is accepted.startRelay.startRelaywith only the env setting a 1000 ms keepalive pings an idle Attach connection. With the env unread, the 20 s default would send nothing in that window.Before and after, with
src/main.tsreverted to main:relayKeepalive is not a function(20 tests). The boot test reportspromise resolved ... instead of rejecting. The env-wiring test reportsexpected 0 to be greater than 0. The three dead-peer tests pass on main, because main already has the keepalive. They are regression cover for the issue's behavior, not the fix. The 8 floor tests added later callrelayKeepalive, which does not exist on main, so they fail there too.Whole package:
pnpm testinpackages/sandbox-relaypasses 26 files and 329 tests;pnpm typecheckis clean;python3 scripts/check-doc-links.pyreports 0 broken links.Out of scope
grpc.http2.min_ping_interval_without_data_msorgrpc.keepalive_permit_without_callson the server. grpc-js's server ignores both, and options that do nothing would mislead readers.Every commit is signed off (DCO).
Assisted-By: Claude Code