Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
Since v32.1 (custom HTTP server, #35182), the server stops calling accept() once -rpcmaxconnections clients are connected (default 16, #35730). Additional clients wait in the kernel's accept queue.
HTTP/1.1 connections are kept alive by default, so a connection keeps its slot after its request has been answered. It's only released when the client closes it, or after -rpcservertimeout (default 30 s) of inactivity. As a result, a client that holds 16 idle keep-alive connections blocks every other RPC and REST client for up to 30 s. That includes bitcoin-cli. Those clients get no error, and nothing is logged; their requests just don't make progress.
In v31 (libevent), the number of concurrent connections was not limited, so this didn't happen.
Real-world example: electrs
electrs (an Electrum server) fetches blocks over REST through its indexing library bindex-rs, which uses the HTTP client ureq 3:
- Blocks are fetched in parallel batches, one request at a time per thread. The number of threads is the number of CPU threads, so on a 32-core machine electrs uses up to 32 REST connections at once, plus one JSON-RPC connection.
- The connections are HTTP/1.1 keep-alive, and up to 32 of them are kept open in a connection pool between requests.
- No request timeout is configured: a request on a connection that bitcoind hasn't accepted waits indefinitely.
When electrs catches up with more than 16 blocks to index (for example after being stopped for a while), each batch of 32 blocks goes like this:
- 16 connections are accepted and served. Their threads finish their blocks, and the connections go back to the client's pool, idle.
- The other 16 threads have sent their requests on new connections, which wait in the accept queue. They can't use the idle pooled connections, because each request is already bound to its own (not yet accepted) connection.
- The batch only completes once the idle connections reach
-rpcservertimeout, bitcoind closes them, and the waiting connections are accepted.
Observed effects:
- Catching up stalls for about 30 s per batch of 32 blocks.
bitcoin-cli getblockcounthangs for the same time, since it waits in the same accept queue.- electrs doesn't react to Ctrl+C or a plain
killduring the stall, because its threads are blocked in requests without a timeout. Onlykill -9stops it right away. - While it's stuck,
ss -tn state established '( sport = :38332 )'lists 29 connections, andss -ltn '( sport = :38332 )'showsRecv-Q 13on the listening socket: 16 accepted connections, and 13 waiting to be accepted.
Setting -rpcmaxconnections=64 makes the problem go away, but there's no hint (error, log message) pointing to it.
Relevant settings
| Setting | Default | Role here |
|---|---|---|
-rpcmaxconnections |
16 | Accepted client connections, busy or idle. At the limit, new connections wait unaccepted in the kernel's accept queue. This is the limit being hit. |
-rpcservertimeout |
30 s | Idle timeout of a connection. In practice it's what frees the slots, so it sets the length of the stall. |
-rpcthreads |
16 | Worker threads; a thread is only busy while a request executes. They're idle during the stall, so this isn't the bottleneck. |
-rpcworkqueue |
64 | Parsed requests waiting for a worker; a full queue gets 503 and a log warning. Not reached, because the waiting requests are never read. |
The two defaults of 16 differ in practice: a thread is held for the milliseconds a request takes, while a connection is held for its whole keep-alive lifetime, including the time spent idle.
Expected behaviour
When the server is at -rpcmaxconnections and new connections are waiting, slots held by keep-alive connections should be freed for them, instead of making every other client wait for -rpcservertimeout. Many HTTP servers handle idle keep-alive connections more aggressively under connection pressure.
Possible improvements:
- While connections are waiting at the limit, answer with
Connection: closeand close the connection after the reply, so that a slot is freed as soon as a request has been answered. This doesn't race with the client, since the client learns from the reply that the connection won't be reused. - For connections that were already idle when the others started waiting (they won't get another reply), disconnect the longest-idle keep-alive client without an in-flight request.
- Log a (rate-limited) warning when the connection limit is reached, pointing to
-rpcmaxconnections. Currently nothing is logged, which makes this hard to diagnose. - Mention in the release notes that clients using more than 16 parallel keep-alive connections need to raise
-rpcmaxconnections.
Steps to reproduce
The following script reproduces it without electrs. It starts 100 concurrent clients. Each one sends a single GET /rest/chaininfo.json and then keeps its connection open, like a client-side keep-alive pool, and prints when it was answered.
- Start bitcoind with
-rest=1(signet RPC port 38332 below). The results below were measured with-rpcmaxconnections=64and the default-rpcservertimeout=30; the same happens with the default of 16. - Run:
import socket, threading, time N = 100 # number of concurrent clients def client(i, t0): s = socket.create_connection(("127.0.0.1", 38332)) # signet RPC port s.sendall(b"GET /rest/chaininfo.json HTTP/1.1\r\nHost: localhost\r\n\r\n") s.recv(65536) print(f"client {i:2} answered after {time.time() - t0:5.1f}s") time.sleep(200) # keep the connection open t0 = time.time() for i in range(N): threading.Thread(target=client, args=(i, t0), daemon=True).start() time.sleep(150)
Results:
- 100 clients,
-rpcmaxconnections=64: 62 clients were answered immediately (0.0 s; 2 slots were in use by another client). The remaining 38 were all answered after 31.1 s, i.e. only once the idle connections reached-rpcservertimeout. - 150 clients: the answers came in three bursts. Each group had to wait for the previous group's idle connections to time out.
-rpcservertimeout=10: the waiting clients were answered after 10–11 s instead of 31 s, so the stall follows the idle timeout exactly.- With the proposed fix: all 100 clients are answered immediately.
Any other client is affected in the same way: while the slots are held by idle connections, bitcoin-cli getblockcount also hangs until the next timeout. While it's blocked, ss -ltn '( sport = :38332 )' shows a non-zero Recv-Q on the listening socket, meaning connections are waiting to be accepted.
Relevant log output
With -debug=http, the waiting clients are only accepted once the idle connections hit the idle timeout. Excerpt from a run of the script above with -rpcmaxconnections=10 -rpcservertimeout=60 (repetitive lines elided):
2026-11-24T11:15:31Z [http] HTTP Connection accepted from 127.0.0.1:54530 (id=0)
2026-11-24T11:15:31Z [http] Received a GET request for /rest/chaininfo.json from 127.0.0.1:54530 (id=0)
... (clients id=1 to id=9 accepted and served the same way)
2026-11-24T11:15:31Z [http] HTTPResponse (status code: 200 size: 970) added to send buffer for client 127.0.0.1:54530 (id=0)
... (all 10 slots now held by idle keep-alive connections; nothing for 61 s)
2026-11-24T11:16:32Z [http] HTTP client idle timeout 127.0.0.1:54530 (id=0)
2026-11-24T11:16:32Z [http] Disconnecting HTTP client 127.0.0.1:54530 (id=0)
... (same for id=1 to id=9)
2026-11-24T11:16:32Z [http] HTTP Connection accepted from 127.0.0.1:54610 (id=10)
2026-11-24T11:16:32Z [http] Received a GET request for /rest/chaininfo.json from 127.0.0.1:54610 (id=10)
... (id=11 to id=19 accepted and served the same way)
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
master @ acdb326. By code inspection, the same applies to v32.0 and v32.1 (httpserver.cpp: the listen sockets aren't polled at the limit, and idle connections are only released by -rpcservertimeout).
Operating system and version
Ubuntu Linux 26.04
Machine specifications
Intel Xeon CPU, 32 cores
Activity
optout21 commentedon Nov 24, 2026
Note: proposed fix is being worked on, currently here: optout21#31
pinheadmz commentedon Nov 24, 2026
Relevant IRC conversation: https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2026-10-29#1270525;
But it was determined that ElectrumX only used 10 connections and they had two instances running. Configuring a higher limit worked. I'm not so sure I'm on board with the eviction of keep alive connections, thats how P2P churns connections but I dont think thats right for HTTP -- would nginx or apache do that?
optout21 commentedon Nov 24, 2026
@pinheadmz , I've seen the mentioned IRC chat, and also comments in #35730, including:
It seems that I have accidentally bumped into such usage:
electrson a host with 16+ cores makes 16+ persistent connections. I know that the easy solution is to sync the configs -- increase bitcoind's maxrpconnections or decrease in electrs, yet I decided this may need some followup, because:Regarding your nginx/apache question, here's what my agent found (I haven't double checked this part):
My proposed fix is actually less aggressive (than nginx's).
fix: default rpcmaxconnections to 64 and stop the onion relay's child…