镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Record why relay connections close and quiet close warnings - #9245

Merged
wpfleger96 merged 2 commits into
mainfrom
duncan/relay-close-reason
Nov 9, 2026
Merged

wpfleger96 merged 2 commits into
mainfrom
duncan/relay-close-reason

Conversation

@wpfleger96

@wpfleger96 wpfleger96 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Since bb-public prod moved to RUST_LOG=error,buzz_relay=info, two connection-close warnings send about 1.9M lines a day to Datadog. This moves that information to the access log and a metric.

  • close_reason on the access close line. The first reason recorded wins. When the server has already decided to close (shutdown, a policy disconnect, or a cancellation), the reader defers to that decision, so a peer's reply to the server's Close is never logged as the cause.
    • Values: auth_timeout, auth_failed (an AUTH rejected and closed immediately, or a timeout after a rejected AUTH), missed_pongs, client_closed, socket_error, frame_too_large, control_channel_full, shutdown, server_closed, refused for connections refused before they were served, and handler_dropped for a handler dropped before normal cleanup.
    • A community disconnect logs its own value: community_archived, community_deleted, auth_policy_upgraded, authorization_denied, access_revoked or removed.
  • The "NIP-42 auth timeout" and "3 missed pongs" warnings are now debug!, with the same text and fields.
  • New counter buzz_ws_missed_pong_disconnects_total, next to buzz_ws_auth_timeouts_total. A heartbeat tick that races a close already decided is not counted.

Timeouts, ping cadence, the frames sent and when connections close are unchanged. The new infra-free tests are added to the test-unit selection and scripts/run-tests.sh.

Add close_reason to the access close line, lower the auth-timeout and
missed-pong warnings to debug, and count missed-pong disconnects.

Co-authored-by: Will Pfleger <wpfleger@block.xyz>
Signed-off-by: Will Pfleger <wpfleger@block.xyz>
@wpfleger96
wpfleger96 requested a review from a team as a code owner November 7, 2026 19:31
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: f3b127e3af5c14d2314faa2b63556c3f51ec6743...7793cfafe3f4e69fb858901632e0efe8c1da3f06
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability regressions identified in the authorized PR range.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source inspection. Builds and tests were not run, as instructed.

Generated by Codex Security Review |
Requested by: @wpfleger96 |
Workflow run

A client's reply to a server Close, a policy or auth-rejection close and a dropped handler now log their real close_reason. The reader defers to a close the server already decided on; a heartbeat tick after cancellation is not counted as a miss.

Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
Signed-off-by: Will Pfleger <wpfleger@block.xyz>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 7, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 7, 2026

@kalvinnchau kalvinnchau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 One finding inline.

return Some(reason.as_str());
}
conn.cancel.is_cancelled().then(|| {
if matches!(conn.auth_state_snapshot(), AuthState::Failed) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [P3] AuthState::Failed does not mean "AUTH was rejected", so unrelated server closes of pending connections can be logged as auth_failed

finish_pending_auth_on_cancel (the auth_cancel_task watcher in handle_active_connection) moves every still-Pending connection to Failed as soon as cancel fires, whatever the cause. It runs concurrently with the reader, so by the time server_close_reason runs (in recv_loop's Close/Err arms, or after recv_loop returns), Failed may have been set by the cancellation itself rather than by a rejected AUTH.

Trigger: an unauthenticated client sends REQs (or malformed frames) without reading. Each gets CLOSED auth-required / NOTICE. Once the send buffer fills, handlers::close::refuse or ConnectionState::send (backpressure) cancels with no disconnect reason. The close line then reads server_closed or auth_failed, depending on whether the watcher ran first. That client never sent AUTH, and the PR description defines auth_failed as "an AUTH rejected". Both tasks wake from the same cancel, so the order is not deterministic.

server_close_reason_ranks_shutdown_policy_then_cancellation builds AuthState::Failed directly, so it does not cover a Pending connection that was flipped by the watcher.

Fix direction: record auth_failed at the rejection sites (where AuthAttempt::reject / deny_admission / the shed path decides to close) before cancelling, as the heartbeat and auth-timeout paths already do, and drop the Failed inference here. If that is too invasive, have finish_pending_auth_on_cancel leave a state distinct from a rejection.

@kalvinnchau kalvinnchau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Approving. The inline P3 (close_reason inferred from AuthState::Failed) is non-blocking.

@wpfleger96
wpfleger96 merged commit 31fa531 into main Nov 9, 2026
110 checks passed
@wpfleger96
wpfleger96 deleted the duncan/relay-close-reason branch November 9, 2026 01:03
bostonaholic added a commit that referenced this pull request Nov 9, 2026
…ction-p

* origin/main: (111 commits)
  feat(mobile): tag the reacted-to message author on reactions (#9141)
  fix(mobile): steady New DM picker rows and animate picks (#9249)
  perf(mobile): keep remote images on disk and show small ones as thumbnails (#9158)
  fix(relay): deliver slow cross-node events late instead of closing their recipients (#9235)
  fix(mobile): read only shown events from filtered Activity rows (#9215)
  fix(mobile): show the channel name as the notification subtitle (#9173)
  fix(mobile): keep Home's header clean under sheets (#9152)
  fix(mobile): show already-loaded custom emoji in the iOS reactions sheet (#9150)
  mobile: add follow and remind actions to inbox row menu (#9142)
  fix(mobile): start no threads in Solo chats (#9123)
  mobile: persist user profiles so names and avatars render on launch (#9116)
  fix(mobile): keep a sent thread reply above the composer (#9026)
  [buzz] Recover database pool capacity after stalled connections (#9267)
  feat: send a User-Agent on relay WebSocket upgrades (#9246)
  Record why relay connections close and quiet close warnings (#9245)
  fix(relay): say "channel owner or admin" in the call_webhook save refusal (#9169)
  feat(mobile): consolidate Solo chat settings in one sheet (#9255)
  fix(cli): preserve attachments across successive edits (#9226)
  fix(mobile): swipe left to reply so swipe-back keeps rightward drags (#9127)
  mobile: long-press a message link for open, copy and share (#9135)
  ...

Signed-off-by: Matthew Boston <mboston@squareup.com>

This branch was previously deployed

1 inactive deployment
codex-review — 7793cfaf Deployed Nov 7, 2026 by wpfleger96 via Run Codex Security Review #13777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants