Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34978. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Sjors
left a comment
There was a problem hiding this comment.
Concept ACK
This does not enforce a hard connection limit at the accept loop
I think it should, because the error for running out file descriptors is presumably confusing, and it will happen at unpredictable moments depending on how many RPC, P2P and IPC connections are active.
It would also be good to cover the number of reserved file descriptors that's printed in the log. If you do that in a test commit before the actual change, that nicely demonstrates that this PR actually increases it.
Regarding the hard connection limit at the accept loop, implementing that would require changes to mp::ListenConnections in libmultiprocess. Would you expect that to be done in this PR, or as a follow-up in libmultiprocess? |
Good question. libmultiprocess should probably give us a hook to (optionally) control the maximum number of connections. It might be good to draft a PR for that on bitcoin-core/libmultiprocess, or at least open an issue. It doesn't have to a pre-requisite for this PR, it could indeed be a followup. |
90ad4dc to
b1abf1a
Compare
kevkevinpal
left a comment
There was a problem hiding this comment.
Concept ACK b1abf1a
I would also update the description to reflect the usage of -unixmaxconnections
b1abf1a to
bd4ef3e
Compare
|
Thanks for the reviews @Sjors @kevkevinpal. I have addressed the comments in the recent push, also updated the PR description to match the changes made. |
|
Concept ACK |
bd4ef3e to
cb2561f
Compare
cb2561f to
37e195d
Compare
|
C.I failure is unrelated |
37e195d to
ac1e51d
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Code review ac1e51db8639e194967454ee0a4da0e8dd7949a0. This looks pretty good, but it looks like there is a problem with negation (see below), and also I made a suggestion about renaming the new option.
Ideally, I think I would want to implement the max connection limit by extending the -ipcbind option instead of introducing a new option. I'd probably extend the -ipcbind syntax to support socat-style options like -ipcbind=unix:/path/to/socket:max-connections=8 when listening on a custom path or -ipcbind=unix::max-connections=10 when listening on the default path. This way different paths (or different transports if we add tcp support) could have different connection limits.
But I can see that a separate option is probably easiest to implement, and it might be useful to users to have an overall cap on the number of connections, so current approach makes sense and might be best for now.
ac1e51d to
bf037b7
Compare
|
Thanks for the reviews so far @ryanofsky @kevkevinpal @Sjors
The socat-style syntax for per-path limits is an interesting idea. Happy to follow up with that approach in a separate PR if there's appetite for it Changes made in this commit are:
|
ryanofsky
left a comment
There was a problem hiding this comment.
Code review ACK bf037b74762220afab8d506c56f7d801b5e6da7e. Strictly speaking I think this PR is an improvement over the status quo, because right now no file descriptors are reserved for IPC and this does reserve some.
But I have the same concerns as Sjors #34978 (review) about how usable the new command line option will be because it only reserves file descriptors for IPC, without limiting how many descriptors IPC uses.
I was also initially concerned that a global limit on number of incoming connections could be more awkward to implement than local limits per listening address, because implementing local limits would just seem to require adding a max_connections parameter to mp::ListenConnections and using a local counter to stop calling ConnectionReceiver::accept when the limit is reached, while a global limit would require adding more state to the EventLoop class. But probably overall complexity of both approaches is about the same.
I'd still prefer local limits, and accepting socat-style max-connections=<n> options in -ipcbind over introducing a new command line option and global limit, but that's not a strong preference.
It would also be nice to see a draft PR with a some complete implementation of connection limiting because it would be a natural followup and could help compare the different approaches.
| assert_equal(result.stderr, None) | ||
| assert_equal(result.returncode, 0 if error is None else 1) | ||
|
|
||
| def test_ipcmaxconnections(self): |
There was a problem hiding this comment.
In commit "test: assert file descriptors available is logged on -ipcbind startup" (dc0583bb8b78ba11c824dc5cb628ab7835f88aee)
I think this file is probably not the right place for these checks, because this file is trying to test bitcoin-cil. Would suggest moving this to interface_ipc.py or adding a new test like interface_ipc_init.py
There was a problem hiding this comment.
Good point, this didn’t really belong in interface_ipc_cli.py. I moved the startup logging coverage into a dedicated interface_ipc_init.py test so the tests are more focused on their intended use
|
|
||
| # Verify FD availability is logged at startup with -ipcbind. | ||
| with self.nodes[0].assert_debug_log(["file descriptors available"]): | ||
| self.restart_node(0) |
There was a problem hiding this comment.
In commit "test: extend -ipcmaxconnections coverage to assert FD reservation logging" (bf037b74762220afab8d506c56f7d801b5e6da7e)
Is there a reason for deleting this test? Maybe it should just be extended to check for the new log string?
There was a problem hiding this comment.
Agreed, I kept the original "file descriptors available" check and extended it in interface_ipc_init.py so the same startup also asserts the new IPC FD reservation log line.
|
|
||
| # Verify FD reservation is explicitly logged with correct values | ||
| with node.assert_debug_log(["Reserving 9 file descriptors for IPC (1 listening sockets, 8 accepted connections)"]): | ||
| self.restart_node(0, extra_args=["-ipcmaxconnections=8"]) |
There was a problem hiding this comment.
In commit "test: extend -ipcmaxconnections coverage to assert FD reservation logging" (bf037b74762220afab8d506c56f7d801b5e6da7e)
It would seem good to just make this the first test and only start the node with -ipcmaxconnections=8 one time, instead of twice.
There was a problem hiding this comment.
Changed that so the first startup uses -ipcmaxconnections=8, and that single restart now checks both the existing startup log and the new reservation log.
bf037b7 to
3c9ff9b
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Code review ACK bf037b74762220afab8d506c56f7d801b5e6da7e. Thanks for the test updates!
One caveat: after reviewing bitcoin-core/libmultiprocess#269 I'm less sure that we will want to add a global -ipcmaxconnections option if we can add per-address limits instead (with -ipcbind max-connections options or something similar).
Either approach should work but should probably pick one before merging any of these PRs.
|
I opened a separate draft PR here #35037 to make the per-address approach concrete downstream using the local listener limit API from bitcoin-core/libmultiprocess#269. That draft uses |
ViniciusCestarii
left a comment
There was a problem hiding this comment.
There doesn’t seem to be a test covering the default behavior when -ipcmaxconnections is not set.
It might be useful to add a case asserting the expected default (16 connections) at test/functional/interface_ipc_init.py:
with node.assert_debug_log([
"file descriptors available",
"Reserving 17 file descriptors for IPC (1 listening sockets, 16 accepted connections)",
]):
self.restart_node(0)
assert_equal(node.getblockcount(), 0)
sedited
left a comment
There was a problem hiding this comment.
Concept ACK
The per-bind accounting seems fine too, but isn't that a bit overkill? Are there really scenarios where different binds or transports would command a completely different number of descriptors?
| } | ||
|
|
||
| // IPC listening socket FDs — one per -ipcbind address, no default listener | ||
| auto ipc_bind = args.GetArgs("-ipcbind").size(); |
There was a problem hiding this comment.
The comment for nBind says "Number of bound interfaces". I think ipc_bind arguably counts towards that too. How about moving that line above the definition of max_private and adding ipc_bind to it?
Click to expand diff
diff --git a/src/init.cpp b/src/init.cpp
index 962b6c9105..86f0efdf6d 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1032,3 +1031,0 @@ bool AppInitParameterInteraction(const ArgsManager& args)
- // Number of bound interfaces (we have at least one)
- int nBind = std::max(nUserBind, size_t(1));
-
@@ -1057,0 +1055,3 @@ bool AppInitParameterInteraction(const ArgsManager& args)
+ // Number of bound interfaces (we have at least one)
+ int binds = std::max(nUserBind + ipc_bind, size_t(1));
+
@@ -1062 +1062 @@ bool AppInitParameterInteraction(const ArgsManager& args)
- int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + nBind + ipc_bind + ipc_max_connections;
+ int min_required_fds = MIN_CORE_FDS + MAX_ADDNODE_CONNECTIONS + binds + ipc_max_connections;There was a problem hiding this comment.
Moving the calculation down and grouping the bound interfaces makes sense, and I applied that in the latest push.
While doing that, I noticed the previous nBind = std::max(nUserBind, size_t(1)) logic had a small pre-existing inaccuracy: it reserves one P2P listener FD even when the node is started with -listen=0.
Also, using std::max(nUserBind + ipc_bind, size_t(1)) directly would undercount in the case where there are no -bind args and one -ipcbind, because the default P2P listener and the IPC listener would together open two listening sockets, but that expression would only reserve one.
So I split the accounting as such
int p2p_binds = args.GetBoolArg("-listen",
DEFAULT_LISTEN) ? std::max(nUserBind, size_t(1)) :
0;
int binds = p2p_binds + ipc_bind;This keeps the grouping you suggested, fixes the old -listen=0 behavior, and accounts for IPC listener without under-reserving.
365be35 to
e175b8a
Compare
When -ipcbind is used, the node opens one listening socket FD per bound address and accepts concurrent IPC connections. Neither was previously accounted for in min_required_fds, meaning IPC-heavy workloads could silently exhaust available file descriptors at unpredictable moments. Add -ipcmaxconnections (default: 16, mirroring -rpcworkqueue) so operators can control how many FDs are reserved for accepted IPC connections. Add ipc_bind to account for the listening socket FDs opened per -ipcbind address, which were previously unaccounted for. Emit a warning when -ipcmaxconnections is set without -ipcbind. Log the total IPC FD reservation at startup so operators can verify it. Suggested by Sjors in bitcoin#32297 (comment).
…ging Add -ipcmaxconnections startup checks and assert the new IPC FD reservation log line fires with correct values. With -ipcmaxconnections=8, the node logs "Reserving 9 file descriptors for IPC (1 listening sockets, 8 accepted connections)", demonstrating that this PR increases the reserved FD count.
e175b8a to
c29e28c
Compare
I don't think the strongest argument for per-address limits is that current transports need wildly different FD budgets. It's more that accepted connections are attached to individual listeners, so per-listener limits are a more natural fit if we later enforce limits in the accept path. For this PR though, since the goal is only startup FD reservation, the global accounting is simpler and probably sufficient. |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
C.I failure is unrelated #35199 |
ryanofsky
left a comment
There was a problem hiding this comment.
Code review c29e28c. Would suggest changing this PR from ready to draft state, because while the accounting logic and test here seem useful, I don't think it would be good to add a new -ipcmaxconnections option that's global and independent from actual IPC interfaces and endpoints.
The related PRs bitcoin-core/libmultiprocess#269 and #35037 seem promising and this PR could build on them using them to control ipc_max_connections. (I'm planning to review them soon.) This PR could also hardcode a small value for ipc_max_connections now and allow it to be configurable later. Then it could be merged independently of the other PRs.
re: #34978 (review)
The per-bind accounting seems fine too, but isn't that a bit overkill? Are there really scenarios where different binds or transports would command a completely different number of descriptors?
It's more straightforward to implement a per-address connnection limit than a global connection limit because each address requires a separate ListenConnections call and ListenConnection calls do not know about each other. A per-address limit also provides an easy-to-understand UX because it doesn't require any new command line options to be added or any command line interactions to be explained. It lets listening options be specified directly along with the listening address.
| } | ||
|
|
||
| // Number of bound interfaces. | ||
| int p2p_binds = args.GetBoolArg("-listen", DEFAULT_LISTEN) ? std::max(nUserBind, size_t(1)) : 0; |
There was a problem hiding this comment.
In commit "init: Reserve file descriptors for IPC connections" (2f731bd)
It seems like this is no longer adding std::max(nUserBind, size_t(1)) to number of required fd's if -listen=0 is used, which seems like a potentially good change, but not related to IPC, and it doesn't seem to be mentioned in the commit description.
If this change will be included I'd suggest making it in a separate commit, or maybe even a separate PR so reviewers more familiar with p2p can ensure it is correct.
|
Marking this PR to draft in favor of #35037 |
|
I'm confused, that PR is also draft and says:
|
|
🐙 This pull request conflicts with the target branch and needs rebase. |
…cbind 856f9ea doc: add ipcbind max-connections release note (Enoch Azariah) bdd381b ipc: test per-address connection limiting over unix sockets (Enoch Azariah) 8761d53 ipc: support per-address max-connections on ipcbind (Enoch Azariah) 3d2b65d ipc: add default connection limit for ipcbind listeners (Enoch Azariah) Pull request description: The branch extends `-ipcbind` to accept `,max-connections=<n>` options, for example `-ipcbind=unix:,max-connections=8` or `-ipcbind=unix:/custom/path,max-connections=8`, instead of introducing a separate global `-ipcmaxconnections` option. This keeps the connection limit attached to each IPC listener instead of introducing a global `-ipcmaxconnections` option (#34978). A global option would not allow different limits for different `-ipcbind` addresses, and the inline option format can be extended in the future with additional options. ACKs for top commit: ryanofsky: Code review ACK 856f9ea. Only change since last review is wrapping the `-ipcbind` help text in `strprintf` so the default and maximum values are shown. Thanks for all the updates! sedited: ACK 856f9ea ViniciusCestarii: re-ACK 856f9ea Tree-SHA512: dd39479372bb5e30d6faedcc3c5f82ba03dbce3a8e082c03c3baf79bca66979554826fab001ca208cefd25955b02f22e6c9cd5bcea7aca1b784f93187f12ab7e
|
Closing this since #35037 has been merged. Thanks for all the reviews here |
… options on -ipcbind 856f9ea158055460764883dfca01491951554d2e doc: add ipcbind max-connections release note (Enoch Azariah) bdd381b8ed475b114d6a8ac25bb448515a2a42f9 ipc: test per-address connection limiting over unix sockets (Enoch Azariah) 8761d53b250e9bb81e59a21d48598c1b62fa0e65 ipc: support per-address max-connections on ipcbind (Enoch Azariah) 3d2b65d050962a35b071618a3f32f7a78831e8e3 ipc: add default connection limit for ipcbind listeners (Enoch Azariah) Pull request description: The branch extends `-ipcbind` to accept `,max-connections=<n>` options, for example `-ipcbind=unix:,max-connections=8` or `-ipcbind=unix:/custom/path,max-connections=8`, instead of introducing a separate global `-ipcmaxconnections` option. This keeps the connection limit attached to each IPC listener instead of introducing a global `-ipcmaxconnections` option (bitcoin/bitcoin#34978). A global option would not allow different limits for different `-ipcbind` addresses, and the inline option format can be extended in the future with additional options. ACKs for top commit: ryanofsky: Code review ACK 856f9ea158055460764883dfca01491951554d2e. Only change since last review is wrapping the `-ipcbind` help text in `strprintf` so the default and maximum values are shown. Thanks for all the updates! sedited: ACK 856f9ea158055460764883dfca01491951554d2e ViniciusCestarii: re-ACK 856f9ea158055460764883dfca01491951554d2e Tree-SHA512: dd39479372bb5e30d6faedcc3c5f82ba03dbce3a8e082c03c3baf79bca66979554826fab001ca208cefd25955b02f22e6c9cd5bcea7aca1b784f93187f12ab7e
When
-ipcbindis used, the node opens one listening socket FD per bound address and accepts concurrent IPC connections. Neither was previously accounted for inmin_required_fds, meaning IPC-heavy workloads could silently exhaust available file descriptors.This PR adds
-ipcmaxconnections(default: 16, mirroring-rpcworkqueue) so operators can control how many FDs are reserved for accepted IPC connections. It also addsipc_bindto account for the listening socket FDs opened per-ipcbindaddress, which were previously unaccounted for. A warning is emitted when-ipcmaxconnectionsis set without-ipcbind.This reserves file descriptors at startup. Upstream PR enforcing the connection limit bitcoin-core/libmultiprocess#269
Note: there is also a draft alternative downstream approach in #35037, using the local per-listener limit API proposed in bitcoin-core/libmultiprocess#269 to support per-address
max-connections=options on-ipcbind.So the two concrete directions under discussion are:
-ipcmaxconnectionsreservation approach in this PR-ipcbind ... max-connections=approach in ipc: support per-address max-connections options on -ipcbind #35037
Suggested by Sjors in #32297 (comment).