Skip to content

Host daemons all drop together when the server event loop stalls past the 30s heartbeat lease (502/504) #6499

Closed

Description

@Waseemilyas

Summary

Every enrolled host daemon drops its connection to the bb server at the same second, several times an hour, because the server event loop stalls past the 30s heartbeat lease. The connect tunnel then closes and session reopen returns 502/503/504. This is not a single machine's network.

Versions and environment

  • bb 0.46.1 on the server and on every enrolled host (latest release at the time of writing is desktop 0.48.0; not yet rolled here)
  • Server: Linux, bb-app.service up since 2026-10-22, process never crashed
  • Hosts: two macOS (arm64), one Linux, plus the server host's own daemon. Daemons were started on different days (26 Oct, 28 Oct 18:46 UTC, 28 Oct 20:47 UTC) and still dropped together
  • Connect URL: https://automancer.getbb.app (tunnel wss://automancer.getbb.app/__tunnel, origin http://127.0.0.1:38886)
  • Host daemon lease: leaseTimeoutMs 30000

What happens

On 2026-10-28 the three remote host daemons logged 99, 100 and 43 Disconnected from server events. 77 timestamps match between the two busiest hosts to the exact second; 26 timestamps match all three hosts exactly, including 2026-10-28 23:14:11 UTC.

Client-side sequence, same on every host:

  1. Server heartbeat acknowledgements stopped; reconnecting (leaseTimeoutMs 30000)
  2. Disconnected from server with code 1013 heartbeat-ack-timeout, code 1006, code 1001 tunnel disconnected, or code 1000
  3. Failed to open session: 502 Bad Gateway / 503 / 504 Gateway Timeout
  4. Connected to server a few seconds later

One client entry names the edge explicitly: code 1000, reason CloudFlare WebSocket proxy restarting.

Disconnect reasons on the busiest host that day: code 1000 (empty) x45, 1013 heartbeat-ack-timeout x39, 1006 x9, 1001 tunnel disconnected x6, 1000 CloudFlare WebSocket proxy restarting x1. Failed to open session that day: 504 x22, 503 x19, 502 x4.

The daemons themselves stayed up (KeepAlive, runs=1, never exited). Disconnects are reconnects, not daemon crashes. Several drops happened while host plugin workers were idle, so this is not head-of-line blocking from a bulk file reply.

Server side, same seconds

~/.bb/logs/server.*.log on the origin, ±60s:

18:11:15 UTC (server.9.log): Event loop stalled with maxDelayMs 14,311 / 9,471 / 14,529. At 18:11:21 [plugin:connect] event loop stalled for 32s; restarting the tunnel heartbeat deadline, then at 18:11:25 tunnel closed (code 1006) with lastHeartbeatAckAgeMs 32,826, and every daemon WebSocket closed. Tunnel reconnected at 18:11:44 (upgradeMs 4,363). read ECONNRESET on an origin GET. Daemon WebSockets reopened at 18:12:08.

21:29:04 UTC (server.10.log): stalls of 16s, 26s, 22s, 16s. At 21:28:58 event loop stalled for 26s. Daemon WebSockets closed and reopened together. At 21:29:57 four level-50 Timed out waiting for command result plus read ECONNRESET on GET /api/v1/sidebar-bootstrap.

23:14:11 UTC: milder stalls (0.7–2.4s) and Thread timeline build blocked the event loop (1,768ms at 23:12:43). At 23:14:10 tunnel closed (code 1006), lastHeartbeatAckAgeMs 4,986 — one second before every client logged code 1001 tunnel disconnected. Tunnel connected again at 23:14:12.

The server process never restarted. It stalled, dropped the tunnel, and recovered. bb machine list still showed every host connected after each reconnect, which hides the gaps.

Expected vs actual

Expected: a host daemon holds its server websocket for hours. A server stall shorter than the lease does not drop every machine.
Actual: stalls of 14–32s blow the 30s lease, the Cloudflare tunnel closes, and every host daemon disconnects and then fails to reopen the session with 502/504 until the tunnel is back.

Related

Suggestion

Keep the connect tunnel and host-daemon lease alive across an event-loop stall longer than 30s, or raise the lease and heartbeat deadline together so a 30s stall is not a full reconnect storm. A timeline build or other server work should not be able to close every machine websocket.

Happy to retest on 0.48.0 if a build after 0.46.1 already changes this. I have not upgraded the production server as part of this report.

Activity

  1. added theissue type on Oct 28, 2026
  2. added
    host
    connect
    partial-repro
    on Oct 28, 2026
  3. bb-slop-cop commented on Oct 29, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · High priority · Medium effort. Applied labels: host, connect, perf, partial-repro.
    • Reproduction and root-cause report — PARTIALLY REPRODUCED, confidence medium, verified in two clean checkouts of trusted main.
    • Verified mechanism: remote clients keep ticking while server acknowledgements stop; three production ServerConnection objects all request reconnect at simulated 35 seconds during a 32-second acknowledgement blackout. Tunnel-local stall grace does not renew remote host leases.
    • Evidence: the 32-second resilience assertion fails in both runs; 14- and 25-second controls pass. Existing host heartbeat/suspension checks (4) and the complete tunnel-client suite (27) pass. The original CPU stall, Cloudflare reset, and HTTP-error chain remain unverified.
    • No PR: the failure is only partially reproduced, and coordinating lease/deadline changes requires a liveness-policy decision outside the simple-fix criteria.

    AGENT GENERATED

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

    connecthostpartial-reproperf

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions