Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down