WIP: RFC: netbase: Remove manual_connection and return the failure reason to callers

bitcoin/bitcoin: PR #36970

2 suggestions

Optional improvements

Link

[suggestion] · getsockopt(SO_ERROR) still bypasses caller-controlled logging

On the rare getsockopt(SO_ERROR) failure path, callers receive an incomplete reason and can add a duplicate diagnostic; no production occurrence was identified.

Location: src/netbase.cpp:614 (head).

Details and suggested fix

If GetSockOpt(SOL_SOCKET, SO_ERROR, ...) fails after Wait reports readiness, this branch still calls LogWarnThenDebug with the OS error but returns only getsockopt() for <dest> failed. That contradicts the new netbase.h contract that failures are not logged internally. Manual-peer and Tor-control callers now add an info-level diagnostic without the OS cause. The internal warning/debug message is unchanged from the base, so after its first occurrence the cause still requires -debug=net. Capture WSAGetLastError() immediately, include NetworkErrorString(err) in the returned Unexpected, and remove the internal log so callers control reporting and receive the complete reason.


Link

[suggestion] · p2p_i2p_ports.py does not require the listen debug message

The follow-up assertion can pass on the SAM-connect message from addnode without observing another Session::Listen failure, leaving the listen site's debug downgrade untested.

Location: test/functional/p2p_i2p_ports.py:41 (head).

Details and suggested fix

The restart phase checks both initial warnings, but the follow-up block expects only Cannot connect to SAM proxy. The outgoing addnode path emits that message through Session::Connect and Hello without calling Session::Listen. Listener retries run separately with a backoff starting at one second and increasing by one second, while this assertion uses the default zero timeout. Its unexpected-warning check therefore need not observe a listener retry, and suppressing subsequent listen diagnostics can go undetected. Also require [i2p] i2p: Couldn't listen: Cannot connect to {self.proxy} with a timeout long enough to observe a listener retry, retaining the unexpected-warning check.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Warning on the first execution of a log statement, then using categorized debug logging, is a deliberate diagnostic policy of LogWarnThenDebug. Its introduction targeted likely system-configuration failures that degrade node functionality and warrant administrator attention, but can recur frequently because of remote activity.

This explains the operational tradeoff behind the helper used at all three affected sites: retain an initial administrator-visible signal without repeatedly emitting unconditional warnings. It establishes the generic first-hit policy, not a separately documented choice of suppression granularity for these particular failures.

Source 1

The related Tor-control discussion distinguished reducing repetitive retry noise from retaining useful operational signals. One proposal favored a warning on the first disconnect or startup failure, an informational message on reconnection, and debug logging for subsequent retries; another participant preferred retaining noisier reporting when Tor was explicitly configured.

This neighboring discussion shows that retry suppression and operator visibility were explicit design considerations, rather than purely mechanical logging changes. However, its wording does not specify whether warnings should rearm after recovery, and it does not settle the intended suppression scope for SAM, I2P listening, or SOCKS failures.

Source 1 · Source 2 · Source 3

Ralph's inferences

The pinned implementation implements process-lifetime suppression independently at each call site. Each macro expansion has one static atomic flag, with no key for proxy identity or error text and no reset after a successful connection. Consequently, later failures at that site use debug logging even for another proxy, another failure reason, or a new outage after recovery. The SAM-connect and I2P-listen sites have separate flags, so the same underlying SAM outage can initially produce both warnings.

This answers what the affected code actually does, while separating that behavior from the narrower historical evidence of intent. I2P listening changes from unconditional error logging to this policy; SOCKS proxy-connect failure gains its own warning-then-debug site; SAM connection failure also has a distinct site.