Skip to content

Fix dev-proxy gRPC-js reconnect backoff so it recovers when the daemon socket appears - #1803

Merged
mstomar125 merged 1 commit into
mainfrom
wt-1551-grpc-backoff
Jul 29, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
wt-1551-grpc-backoff

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #1551.

Problem

The Bun dev-proxy builds its gRPC-js client once at startup. When the proxy starts before the daemon binds its socket (which DaemonTestHarness.startDeferred() does deliberately), the channel's subchannel enters an ever-growing reconnect backoff (grpc-js default 1s→120s) that is independent of the socket actually becoming reachable moments later — so the next RPC fails silently with UNAVAILABLE. A real gap in the ADR-048 e2e harness that a raw socket probe can't detect. The production Tauri/tonic path has no equivalent cached-backoff state and is untouched.

Fix

  • Extract the gRPC client setup into packages/dev-tools/src/grpc-client.ts so the not-ready→recovered behavior is regression-testable in isolation.
  • Bound the reconnect backoff to a fixed ~100ms via grpc.initial_reconnect_backoff_ms / grpc.max_reconnect_backoff_ms — the channel re-probes ~10×/second and recovers within ~100ms of the socket appearing (verified: ~127ms with the fix vs ~2234ms without).
  • Gate every RPC (and the WatchNodes bridge) on client.waitForReady(deadline) so a call issued right after the daemon binds waits for READY instead of failing instantly.
  • Add dev-proxy-recovery.e2e.ts: one RPC issued before a late-binding stub server, asserted to resolve promptly with no real-RPC polling. It fails without the fix and passes with it.
  • Simplify DaemonTestHarness.waitUntilProxyReady() to socket reachability now that the proxy self-heals at the source.

Notes

  • I read grpc-js 1.14.4's source to confirm the mechanism: the backoff lives on the subchannel; pick-first's resetBackoff is a no-op and startConnecting() doesn't restart the timer — so bounding the backoff via channel options is the only public lever that works. Documented in the module header.
  • @grpc/[email protected] + @grpc/proto-loader added as desktop-app devDependencies for the test only; the community/production bundle is unaffected (production uses tonic). Root already pins grpc-js to 1.14.4.

Verification

Full pre-push gate green (test:all + daemon build + e2e). New regression test + the startDeferred() recovery test both pass against a real daemon.

…n socket appears

The Bun dev-proxy built its gRPC-js client once at startup. When the proxy
started before the daemon bound its socket, the channel's subchannel entered
an ever-growing reconnect backoff (grpc-js default 1s->120s) independent of
the socket actually becoming reachable moments later, so the next RPC failed
silently with UNAVAILABLE — a real gap in the ADR-048 e2e harness that a raw
socket probe could not detect.

- Extract the gRPC client setup into dev-tools/src/grpc-client.ts so the
  not-ready -> recovered behavior is regression-testable without the full proxy
- Bound the reconnect backoff to a fixed ~100ms via channel options
  (grpc.initial_reconnect_backoff_ms / grpc.max_reconnect_backoff_ms) so the
  channel re-probes ~10x/second and recovers within ~100ms of the socket
  appearing, regardless of how long the daemon was down
- Gate each RPC (and the WatchNodes bridge) on client.waitForReady(deadline)
  so a call issued right after the daemon binds waits for READY instead of
  failing instantly
- Add dev-proxy-recovery.e2e.ts: one RPC issued before a late-binding stub
  server, asserted to resolve promptly with no real-RPC polling
- Simplify DaemonTestHarness.waitUntilProxyReady() to socket reachability now
  that the proxy self-heals at the source

The production Tauri/tonic path has no equivalent cached-backoff state and is
untouched. grpc-js/proto-loader added as desktop-app devDependencies for the
test only; community/production bundle unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE — Independent review + adversarial re-review both CONFIRMED. Empirically validated the fix (channel recovers ~127ms after socket bind vs ~2234ms unpatched; the regression test genuinely fails without the fix). Refactor is behavior-preserving (same proto paths/loader options), waitForReady guarantees no unbounded hang (rejects at deadline), simplified waitUntilProxyReady() verified safe for its sole caller, and the added grpc-js deps are dev-only (community/production tonic path untouched). Full pre-push gate green.

@mstomar125
mstomar125 merged commit 567b706 into main Jul 29, 2026
2 checks passed
@mstomar125
mstomar125 deleted the wt-1551-grpc-backoff branch July 29, 2026 07:00
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.

dev-proxy's gRPC-js channel can carry forward reconnect backoff past daemon readiness

1 participant