Skip to content

Add peer address to N2_ConnectError trace events#12864

Open
hsson wants to merge 2 commits intoapple:mainfrom
hsson:add-peer-ip-to-trace-logs
Open

Add peer address to N2_ConnectError trace events#12864
hsson wants to merge 2 commits intoapple:mainfrom
hsson:add-peer-ip-to-trace-logs

Conversation

@hsson
Copy link
Copy Markdown

@hsson hsson commented Mar 26, 2026

The N2_ConnectError trace events were missing the peer IP address, making it difficult to identify which remote host failed to connect. This change adds PeerAddr and PeerAddress fields to all three N2_ConnectError logging locations in Net2.actor.cpp:

  • Connection::connect() for regular TCP connections
  • SSLConnection::connect() for TLS connections
  • SSLConnection::connectWithHostname() for TLS with SNI

The BindPromise class already supported peer address logging, but setPeerAddr() was not being called for connection errors. This follows the same pattern used for other network error trace events (e.g., N2_ReadError, N2_WriteError, N2_AcceptHandshakeError) which already include peer address information.

Code-Reviewer Section

The general pull request guidelines can be found here.

Please check each of the following things and check all boxes before accepting a PR.

  • The PR has a description, explaining both the problem and the solution.
  • The description mentions which forms of testing were done and the testing seems reasonable.
  • Every function/class/actor that was touched is reasonably well documented.

For Release-Branches

If this PR is made against a release-branch, please also check the following:

  • This change/bugfix is a cherry-pick from the next younger branch (younger release-branch or main if this is the youngest branch)
  • There is a good reason why this PR needs to go into a release branch and this reason is documented (either in the description above or in a linked GitHub issue)

@hsson hsson force-pushed the add-peer-ip-to-trace-logs branch from 68b86e8 to 5dac94c Compare March 26, 2026 12:24
The N2_ConnectError trace events were missing the peer IP address,
making it difficult to identify which remote host failed to connect.
This change adds PeerAddr and PeerAddress fields to all three
N2_ConnectError logging locations in Net2.actor.cpp:

- Connection::connect() for regular TCP connections
- SSLConnection::connect() for TLS connections
- SSLConnection::connectWithHostname() for TLS with SNI

The BindPromise class already supported peer address logging, but
setPeerAddr() was not being called for connection errors. This follows
the same pattern used for other network error trace events (e.g.,
N2_ReadError, N2_WriteError, N2_AcceptHandshakeError) which already
include peer address information.
@hsson hsson force-pushed the add-peer-ip-to-trace-logs branch from 5dac94c to a9429da Compare March 26, 2026 12:27
Copy link
Copy Markdown
Collaborator

@gxglass gxglass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The existing API seems obviously error-prone in retrospect. Do you think it would make sense to make the peer_address value be a parameter to the BindPromise constructor? Worst case, callers type NetworkAddress() and get a value with a bunch of zeros.

The previous API was error-prone as callers could forget to call
setPeerAddr() after construction. By making peerAddr a required
parameter, callers must consciously provide it (or NetworkAddress()
if truly not applicable).

Changes:
- BindPromise constructors now require peerAddr parameter
- Removed setPeerAddr() method
- Updated all call sites to pass peer address at construction
- Added comments for AcceptError cases where peer is unknown
@hsson
Copy link
Copy Markdown
Author

hsson commented Mar 27, 2026

Thanks. The existing API seems obviously error-prone in retrospect. Do you think it would make sense to make the peer_address value be a parameter to the BindPromise constructor? Worst case, callers type NetworkAddress() and get a value with a bunch of zeros.

Thanks for the feedback, pushed another commit now that makes the peer address a mandatory parameter in the constructor! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants