Repository navigation
fix(relay): report event-loop freezes and keep seat polls off the cell-list read - #27405
Conversation
…oop freezes The seat poller no longer waits on its database cell-list read before polling cells once it has a list, so a stalled read cannot starve the polls that feed a reserve cell's dead-man. Runtime metrics add eventLoopDelayMsMax: a single long freeze is one sample, so p99 read 68 ms across a 134 s staging freeze. Adds a pool test against a database that accepts and never answers, and a real-Postgres stop/start recovery test.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to The runtime changes add an event-loop delay metric and let seat polling continue during a cell-list refresh. The remaining concerns are in the new connection-stall tests: one assertion can fail spuriously, and one timer can linger after a failed test. Neither affects production behavior, but both are worth tightening before merge. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a253152b-5521-453c-9752-2b5f75a07f17
📒 Files selected for processing (5)
cloud/apps/relay/src/database-connect-stall-postgres.test.tscloud/apps/relay/src/relay-observability.test.tscloud/apps/relay/src/relay-observability.tscloud/apps/relay/src/shadow-seat-directory.test.tscloud/apps/relay/src/shadow-seat-directory.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| // A queued caller waits out one connect timeout for a slot, then one for its own dial. | ||
| expect(elapsedMs).toBeLessThan(4_500) | ||
| } | ||
| expect(stalling.sockets.size).toBeGreaterThan(0) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Count accepted connections, not connections still open.
When the stalled connections close before Promise.all settles, the server’s close handler removes them from stalling.sockets. The pool can then fail every query as intended while this assertion fails. Record an accepted-connection count when the server receives a connection, and assert on that count instead. pg-pool destroys a connecting client when its connection timeout expires. (raw.githubusercontent.com)
| function watchEventLoop(): { stop: () => number } { | ||
| let last = performance.now() | ||
| let longestGapMs = 0 | ||
| const timer = setInterval(() => { |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Clear the event-loop interval during test cleanup.
If an assertion in the PostgreSQL-gated test fails before loop.stop(), afterEach closes the pool and server but leaves this interval active. An active interval keeps the Node.js event loop running and can delay test-worker shutdown. Register interval cleanup when watchEventLoop() creates it, or use try/finally around the test. (nodejs.org)
ELI5
When the relay's database was starting up on staging (2026-10-11), both directors stopped doing anything at all for about two and a half minutes. Our dashboards showed nothing unusual. This PR makes that kind of freeze visible, removes a small wait in the seat poller that could make it worse, and adds tests showing the database pool fails fast when the database accepts connections but never answers.
The fix for the freeze itself is a separate Terraform PR, which moves the director onto a Cloud SQL Auth Proxy sidecar. This PR doesn't change how the director connects.
What Changed
eventLoopDelayMsMax, the longest stall in the interval. Before, the line reported only the p99, which read 67.9 ms across a 134 s freeze: one long freeze is a single sample, so it never reaches the 99th percentile. The max captures it.database-connect-stall-postgres.test.ts.ORCA_RELAY_TEST_POSTGRES_URLis set. It puts a proxy in front of a real PostgreSQL and moves it through stop (refuse), start-up (accept but never answer) and back up. Each phase fails fast and retryably, and the pool serves again afterwards.Why
Root cause. On Cloud Run's built-in Cloud SQL socket,
connect()itself blocks until the connector's dial to the instance finishes. That dial timed out after 10 s on each try while the instance started. The awaits ran back to back without returning to the event loop, so no timer could fire for 134 s:Evidence is in the staging logs from 06:12:14 to 06:14:28 on 2026-10-11:
Production showed the same signature once in the last 14 days, on 2026-09-28 at about 14:09–14:11 UTC. Four directors each lost 40–50 s.
Why these changes. They don't fix the blocking connect; the sidecar PR does that. They make the next freeze show up in metrics, and they lock in, with tests, the fail-fast behaviour the sidecar relies on over TCP. No in-process test can reproduce a blocking
connect(); the staging stop/start drill after the sidecar merge covers that.Alternatives considered.
Linked Issue
N/A (internal relay incident follow-up, staging 2026-10-11).
Visual Proof
N/A: no UI. Only the metrics line and tests change.
Testing
vitest runfor the whole relay app: 1108 passed, 188 skipped (Postgres-gated tests).database-connect-stall-postgres.test.tsagainst a local PostgreSQL 16 (ORCA_RELAY_TEST_POSTGRES_URLset): both cases pass in about 2 s each.expected [ 'cell-a.example.test' ]to equal two polls).tsc --noEmitpasses for the relay app.AI Disclosure
N/A (internal contributor).
Agent skill upstream boundary
Notes
eventLoopDelayMsMaxfield reaches cells on their next normal roll.Checklist
tscandvitestpass locally