mirror of
https://github.com/block/buzz.git
synced 2026-11-28 12:12:04 +00:00
## Summary
The relay's Redis pub/sub subscribers (event fan-out, cache
invalidation, community connection control, NIP-FI disconnects) waited
on their message streams with no deadline. A socket the network dropped
silently looked like a quiet channel, and the pod missed every message
on it until it restarted.
A shared `keepalive` helper in `buzz-pubsub` now bounds every pub/sub
connection:
- **Setup and control requests.** Connect, handshake, and every
`SUBSCRIBE`/`PSUBSCRIBE`/`UNSUBSCRIBE` (including the fan-out
subscriber's dynamic subscribes and confirmations) must get a reply
within 5 s.
- **Heartbeat.** A single pinned future, polled next to the message
stream, sends `PING` every 15 s and fails if a reply doesn't arrive
within 5 s. Messages keep being forwarded while a `PING` is pending, and
incoming traffic can't reset its deadline.
- **Exit.** Any missed deadline returns an error from the connection
function, dropping both halves of the connection (closing the socket).
The existing reconnect loop with backoff takes over.
A dead socket is detected within about 20 s (15 s interval + 5 s
deadline) under normal scheduling. Reconnect backoff comes on top of
that. Messages that weren't read before the connection is dropped aren't
replayed by this change.
## Tests
The tests run against a scripted RESP2 server in the test module, which
can withhold `PING` or subscribe replies, push messages, and report when
a client socket closes. They need no Redis and are added to `just
test-unit` and `scripts/run-tests.sh`.
-
`conn_control::tests::keepalive::nip_fi_subscriber_forwards_while_pong_withheld_then_drops_socket`:
with a `PING` reply withheld, a NIP-FI disconnect is delivered before
the subscriber exits. With the reply never sent, the subscriber returns
a timeout and its socket closes. Fails if the loop awaits `PING` inline.
-
`subscriber::tests::keepalive::stalled_dynamic_confirm_is_not_confirmed_and_drops_socket`:
a stalled dynamic subscribe isn't confirmed, and the connection is
dropped. Fails without the subscribe deadline.
-
`conn_control::tests::keepalive::conn_control_subscriber_drops_socket_when_pong_withheld`
-
`conn_control::tests::keepalive::nip_fi_subscriber_fails_stalled_subscribe`
-
`subscriber::tests::keepalive::subscriber_drops_socket_when_pong_withheld`
-
`cache_invalidation::tests::subscriber_drops_socket_when_pong_withheld`
- `keepalive::tests::{heartbeat_fails_when_pong_withheld,
heartbeat_keeps_running_while_pongs_arrive,
bounded_fails_stalled_subscribe}`
---------
Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Co-authored-by: Hayt <211b96e6a2b7f45fd4047988976c7bbbeeda0c15f3ae7b32eec20834b5a55118@buzz.block.builderlab.xyz>