Skip to content

Survive transient relay crashes + add restart policy#20

Merged
dsbaars merged 1 commit into
mainfrom
fix/relay-crash-resilience
Jun 30, 2026
Merged

Survive transient relay crashes + add restart policy#20
dsbaars merged 1 commit into
mainfrom
fix/relay-crash-resilience

Conversation

@dsbaars

@dsbaars dsbaars commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

Production bunker was offline for ~2 days. The server process crashed on an uncaught SendingOnClosedConnection thrown by nostr-tools asynchronously from a WebSocket open handler — during a relay reconnect storm a subscription re-fired on a socket that had closed mid-reconnect. The throw happens in the ws event loop, not our call stack, so the try/catch around pool.subscribe can't catch it. With no restart: policy in compose, the container then stayed down.

Fix

  • Process guards (uncaughtException / unhandledRejection): swallow the transient relay error (the connection watchdog re-subscribes the dropped relay shortly after) and exit(1) on any genuine fault, so a real bug still fails fast and the container restarts cleanly instead of limping in an undefined state. Unit-tested.
  • restart: unless-stopped on all compose services so a crash or host reboot auto-recovers.

Notes

  • Already applied docker update --restart unless-stopped to the live mini7 containers as an immediate mitigation; this PR makes it survive up -d --build.
  • Possible follow-up (not in this PR): dampen the relay reconnect churn (relay.primal.net/relay.damus.io were rejecting with too many concurrent REQs), which is what triggers the transient error.

A relay reconnect storm made nostr-tools throw SendingOnClosedConnection
asynchronously from a WebSocket 'open' handler (it re-fires a subscription
on a socket that closed mid-reconnect). The throw escapes our try/catch
and surfaced as an uncaughtException that killed the bunker process; with
no restart policy the container then stayed down for days.

- Add process guards (uncaughtException/unhandledRejection): swallow the
  transient relay error (the watchdog re-subscribes shortly after) and
  exit on any genuine fault so the container restarts cleanly.
- Add `restart: unless-stopped` to all docker-compose services so a crash
  or host reboot auto-recovers instead of leaving the bunker offline.
@dsbaars dsbaars merged commit 1a9c6c3 into main Jun 30, 2026
4 checks passed
@dsbaars dsbaars deleted the fix/relay-crash-resilience branch June 30, 2026 19: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.

1 participant