Skip to content

fix(electrum): stop logging full response payload on client disconnect#223

Open
EddieHouston wants to merge 1 commit into
Blockstream:new-indexfrom
EddieHouston:client-disconnect-huge-log-fix
Open

fix(electrum): stop logging full response payload on client disconnect#223
EddieHouston wants to merge 1 commit into
Blockstream:new-indexfrom
EddieHouston:client-disconnect-huge-log-fix

Conversation

@EddieHouston

Copy link
Copy Markdown
Collaborator

Problem

A client that disconnects mid-response (broken pipe / connection reset) caused the entire JSON-RPC reply to be logged at ERROR. For large replies — e.g. a blockchain.scripthash.get_history result for a very popular address — this dumped a multi-megabyte line to stderr, which Cloud Logging then split across many ERROR entries.

Root cause chain in src/electrum/server.rs:

  1. send_values() built its error context with format!("failed to send {}", value), embedding the entire reply Value into the error string.
  2. That error propagated up to run() and was logged via error!(... e.display_chain() ...).
  3. stderrlog writes to stderr, which GKE/Cloud Logging tags as ERROR severity by default.

Fix

  • Truncate the send-failure context to a byte count instead of the full payload:
    .chain_err(|| format!("failed to send response ({} bytes)", line.len()))?;
  • Add an is_disconnect() helper that walks the error source() chain for BrokenPipe | ConnectionReset | ConnectionAborted | UnexpectedEof.
  • In run(), route client disconnects to debug! (expected, not actionable) while genuine failures still log at error!.

Result

No more multi-megabyte ERROR spam. A client disconnecting mid-response now produces a single concise debug! line; real write/protocol failures remain at error! without the payload.

  Broken-pipe/reset errors during send embedded the entire JSON-RPC reply
  (e.g. a large get_history result) into the error context, which was then
  logged at ERROR and split across many Cloud Logging entries. Truncate the
  send-failure context to a byte count and route client disconnects to debug!.
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