From c71b464d108ceab21d7bd6b3c5b389f8da9eb952 Mon Sep 17 00:00:00 2001 From: Wan Nur Shafiqah <176239359+shanurwan@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:04:19 +0800 Subject: [PATCH] fix(daemon): retry when bitcoind's RPC work queue is full When -rpcworkqueue is full, bitcoind answers HTTP 503 with the body "Work queue depth exceeded". into_jsonrpc_body turned every status other than 200 and 500 into a plain error, so retry_request returned it instead of retrying, and electrs exited: ERROR server failed: Error: request failed "HTTP/1.1 503 Service Unavailable": ... = "Work queue depth exceeded" Seen on testnet4 with bitcoind started with -rpcworkqueue=2 -rpcthreads=1 while other clients called getblock. A busy bitcoind recovers once its queue drains, so treat 503 like a dropped connection: the singleton path waits, reconnects and retries, as it does during warmup (-28), and the client path reports the daemon as unavailable. --- src/daemon.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/daemon.rs b/src/daemon.rs index 6fff139e1..bdd9622f8 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -1048,6 +1048,16 @@ impl HttpResponse { debug!("RPC HTTP 500 error: {}", self.body); Ok(self.body) // the body should have a JSONRPC error field } + // bitcoind answers 503 "Work queue depth exceeded" when its RPC work queue + // (-rpcworkqueue) is full. That clears once the queue drains, so treat it like a + // dropped connection: the singleton path waits, reconnects and retries, as it does + // during warmup, and the client path reports the daemon as unavailable. As a plain + // error it ended the main loop and stopped electrs. + "HTTP/1.1 503 Service Unavailable" => bail!(ErrorKind::Connection(format!( + "daemon is busy status='{}' body='{}'", + self.status, + self.body.trim() + ))), _ => bail!( "request failed {:?}: {:?} = {:?}", self.status, @@ -2273,6 +2283,33 @@ mod tests { assert_eq!(handshake_count(&config, "error"), 0); } + #[test] + fn recv_treats_a_full_work_queue_as_a_connection_error() { + // What bitcoind sends when -rpcworkqueue is full. As a connection error, the singleton + // path waits and retries instead of ending the main loop. + let (mut connection, server) = fake_daemon(secs(5), |mut socket| { + let body = "Work queue depth exceeded"; + let _ = socket.write_all( + format!( + "HTTP/1.1 503 Service Unavailable\r\nContent-Length: {}\r\n\r\n{}", + body.len(), + body + ) + .as_bytes(), + ); + thread::sleep(millis(200)); + }); + + let err = connection.recv().unwrap_err(); + let msg = connection_error(&err); + assert!( + msg.contains("daemon is busy") && msg.contains("Work queue depth exceeded"), + "expected a busy daemon connection error, got {:?}", + msg + ); + server.join().unwrap(); + } + #[test] fn recv_treats_an_empty_forbidden_as_a_connection_error() { // So the singleton path reconnects and retries, and the client path reports the