Skip to content

fix(relay): raise grace limit, add replay backpressure, and NOTICE on oversized frames#1226

Merged
wpfleger96 merged 1 commit into
mainfrom
wpfleger/fix-relay-disconnects
Jun 24, 2026
Merged

fix(relay): raise grace limit, add replay backpressure, and NOTICE on oversized frames#1226
wpfleger96 merged 1 commit into
mainfrom
wpfleger/fix-relay-disconnects

Conversation

@wpfleger96

@wpfleger96 wpfleger96 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follows #1225 (configurable frame limit, now merged). Addresses the remaining relay disconnect causes that #1225 did not cover.

Changes

  • Raise slow-client grace limitSLOW_CLIENT_GRACE_LIMIT from 3 to 15, configurable via BUZZ_SLOW_CLIENT_GRACE_LIMIT. The previous value of 3 consecutive buffer-full try_send calls was too aggressive with Istio multi-hop buffering and increased fan-out from more subscribers per channel.
  • Add replay backpressure — yield to the tokio runtime every 100 events during REQ historical replay so the send_loop can drain between batches, preventing buffer overflow mid-replay.
  • Lower historical replay limitMAX_HISTORICAL_LIMIT from 10,000 to 2,000. Reconnecting clients rarely need 10k events of backfill. This reduces the worst-case replay burst that can overflow the send buffer.
  • Send NOTICE before oversized-frame disconnect — on top of [codex] Make relay frame limit configurable #1225's frame-limit fix, the client now receives ["NOTICE","error: frame too large (N bytes, limit M)"] before the connection closes, giving a diagnostic instead of a silent disconnect.

Infra follow-up

Separately, BUZZ_SEND_BUFFER should be raised from 1,000 to 8,000 in block-coder-tf-stacks staging values.yaml to further absorb replay and fan-out bursts.

@wpfleger96 wpfleger96 force-pushed the wpfleger/fix-relay-disconnects branch from 0a553bf to c9f49c8 Compare June 24, 2026 00:15
@wpfleger96 wpfleger96 changed the title fix(relay): raise frame limit, grace limit, and add replay backpressure fix(relay): raise grace limit, add replay backpressure, and NOTICE on oversized frames Jun 24, 2026
Staging relay disconnects spiked this week as user count grew. Three
independent causes compound into a reconnect storm:

1. MAX_FRAME_BYTES was 64 KiB but NIP-44 encrypted observer/engram
   events produce ~88 KiB frames after base64 expansion — silent
   disconnect, no error to client.

2. SLOW_CLIENT_GRACE_LIMIT was 3 consecutive buffer-full events —
   too aggressive with Istio multi-hop buffering and fan-out bursts
   from more subscribers per channel.

3. REQ historical replay sends up to 10,000 events in a tight
   try_send loop with no yielding, overflowing the 1,000-message
   send buffer and triggering the grace limit mid-replay.

Changes:
- Raise MAX_FRAME_BYTES default to 512 KiB, configurable via
  BUZZ_MAX_FRAME_BYTES. Send NOTICE before disconnecting on
  oversized frames.
- Raise SLOW_CLIENT_GRACE_LIMIT default to 15, configurable via
  BUZZ_SLOW_CLIENT_GRACE_LIMIT.
- Lower MAX_HISTORICAL_LIMIT from 10,000 to 2,000.
- Yield to the runtime every 100 events during replay so the
  send_loop can drain between batches.
@wpfleger96 wpfleger96 force-pushed the wpfleger/fix-relay-disconnects branch from c9f49c8 to ba2b3b4 Compare June 24, 2026 00:21
@wpfleger96 wpfleger96 merged commit 142a5c9 into main Jun 24, 2026
28 checks passed
@wpfleger96 wpfleger96 deleted the wpfleger/fix-relay-disconnects branch June 24, 2026 00:26
wpfleger96 added a commit that referenced this pull request Jun 24, 2026
…est helper

The conn_manager.register() signature has required a grace_limit: u8
argument since #1226. #1227's register_presence_sub helper was added
with only 5 args, breaking the buzz-relay test build (E0061). Matches
the sibling register_conn helper's value of 3.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
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.

2 participants