Repository navigation
zmq: Log bind error at Error level, abort startup on init error - #35902
chriszeng1010 wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy 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. |
|
Can you drop the second commit? We don't typically change these names in separate drive-by commits. |
3ec247b to
d9c4e5f
Compare
Okie. Done. |
|
Concept ACK. Built and tested locally with a variety of zmq misconfigurations, permissioned ports, busy ports, etc. Before I review the code I just noticed that the error reason is not bubbled up to stdout, and I wonder if we can do that? Example: reason is "Failed to bind address, msg: Permission denied" Example: reason is "Failed to bind address, msg: Address already in use" etc... |
d9c4e5f to
cdca6ca
Compare
|
I refactored the Initialize()'s return type to util::Result and it returns the error code and failure reason. Tested: $ mkdir -p /tmp/zmqcheck |
| self.restart_node(0, ["-zmqpubrawtx=foo", "-zmqpubhashtx=bar"]) | ||
| # Invalid zmq arguments should cause exit with an error | ||
| self.stop_node(0) | ||
| self.nodes[0].assert_start_raises_init_error(extra_args=["-zmqpubrawtx=foo", "-zmqpubhashtx=bar"]) |
There was a problem hiding this comment.
Now that you've got the error messages spitting out, can we cover a few specifically with the functional test? See how other tests add expected_msg to this check
cdca6ca to
beeba77
Compare
|
Latest push should fix broken CI. |
beeba77 to
97c7f61
Compare
| expected_msg="Error: Failed to bind address bar for pubhashtx: .+", | ||
| match=ErrorMatch.PARTIAL_REGEX, |
There was a problem hiding this comment.
Why use the regex here? You should be able to assert that the error is exactly this, right?
Error: Failed to bind address foo for pubrawblock: Invalid argument
Also I'd like to see a test covering the other expected errors:
(IP not available locally)
Error: Failed to bind address tcp://1.2.3.4:100 for pubrawblock: Can't assign requested address
(Port in use already by RPC -- will need to use rpc_port() in the test framework)
Error: Failed to bind address tcp://127.0.0.1:18443 for pubrawblock: Address already in use
|
Approach ACK. Built and ran One small observation is that the PR description is stale relative to the head (Code path and Testing). |
3f27348 to
194a159
Compare
|
Added new test cases and verified locally on Windows OS. Linux/MacOS are pending CI. I replaced the Regex with a string check. Since the error string after Also, in the test case we point |
Co-authored-by: Ash Manning <[email protected]> Co-authored-by: Chris Zeng <[email protected]>
194a159 to
311847f
Compare
|
Can the reviewers please take a look at this PR? Thanks. |
|
|
||
| #ifdef ENABLE_ZMQ | ||
| g_zmq_notification_interface = CZMQNotificationInterface::Create( | ||
| auto notifiers{CZMQNotificationInterface::GetNotifiers( |
There was a problem hiding this comment.
I don't understand why you need this GetNotifiers intermediate function. I would just expect to see CZMQNotificationInterface::Create() return a Result bubbling up from CZMQNotificationInterface::Initialize() as it attempts to call CZMQAbstractNotifier->Initialize() on each member of notifiers
|
@chriszeng1010 are you still working on this? There is an unaddressed review comment. |
|
Thanks for the ping. Yes i am. |

History
This picks up #33727, which was closed for inactivity
Problem
Currently when a user configures -zmqpub* and the socket can't be bound, the program proceeds normally. The only trace is a debug-level log line that's invisible in a default configuration.
#33715 hit this when their port was already taken.
What this PR does
The node refuses to start if ZMQ is configured and setup failed. This failure is now logged at error level.
Code path:
GetNotifiers builds the notifier objects from the config; Create initializes them — starts the ZMQ engine and binds each socket. When initialization fails, Initialize() returns a util::Result carrying an error that names the notifier, the address and the OS error. Create() propagates it and init.cpp returns InitError with that message. On a node with no -zmqpub* option, the notifier list is empty.
Why abort?
#17445 fixed bitcoind crash from bad assert due to ZMQ config (issue #17185).
Issue #33715 reports that when ZMQ port was already taken, bitcoind started but user could not see anything with getzmqnotifications. Maintainers at the time agreed it should log louder and abort at startup. Which is what this PR fixes.
Testing
bitcoind -regtest -zmqpubhashblock=foo
Result: exits with code 1, and prints:
interface_zmq.py asserts the exact full error message for five startup-failure cases: invalid address, invalid address on a later notifier after an earlier one bound successfully (partial success must still abort), unreachable IP (EADDRNOTAVAIL), and a port already taken by the node's own RPC server (EADDRINUSE, via rpc_port()). The expected errno text is derived with os.strerror on the platform running the test, since the string after the last ":" differs per platform; on Windows the two strings libzmq hardcodes are pinned instead.
Verified locally on Windows; the full CI matrix is green on my fork.
A node with no -zmqpub* options starts exactly as before — nothing changes for nodes that don't use ZMQ.