3 suggestions
Optional improvements
[suggestion] · Send-path pause initialization is untested
Both pauses start in PushMessage, leaving SocketSendData's timer initialization untested; no measured production case entering that branch was identified.
Location: src/test/net_tests.cpp:201 (head).
Details and suggested fix
Each new pause episode queues a 2048-byte payload against a 1024-byte limit, so PushMessage sets fPauseSend before its optimistic send. The explicit send starts already paused, and the drain only clears the pause. Removing the timestamp update under pause_send && !node.fPauseSend in SocketSendData would therefore leave these assertions satisfied. A pause first detected by that path could then retain an epoch or stale timestamp instead of starting its own interval. Add a separate V1/null-socket case that queues below the limit, lowers nSendBufferMaxSize using Init, and calls SocketSendDataPublic. Assert that it pauses, records the current mock time, and respects the existing exclusive TIMEOUT_INTERVAL boundary.
[suggestion] · Timer preservation after partial sends is untested
The unit test moves bytes only when fully draining, so it would miss a regression that restarts the pause deadline on successful partial sends while usage remains above the limit.
Location: src/test/net_tests.cpp:185 (head).
Details and suggested fix
The null-socket attempts exit before the successful-send branch, while ZeroSock::Send accepts every byte and clears the pause. Refreshing m_last_send in inactive() does not exercise a reset of m_pause_send_since inside the positive-send path. Such a regression could pass this test and keep extending the paused-send deadline for a peer making partial progress. Add a ZeroSock subclass whose Send accepts only a small prefix. V1 retains the payload allocation until completion, so a partial write can leave usage above 1024 bytes. Assert that nSendBytes increased and fPauseSend remains true, then check that the original timestamp is unchanged and expiration still occurs only after the original TIMEOUT_INTERVAL.
[suggestion] · Recovery and re-pausing use the same mock timestamp
The recovery and next pause share a mock timestamp, so the unit test cannot distinguish a timer started on recovery from one started on re-pausing.
Location: src/test/net_tests.cpp:201 (head).
Details and suggested fix
ZeroSock drains at first_pause + TIMEOUT_INTERVAL + 1s, and the next queue_message() runs without another clock advance. Both m_pause_send_since == NodeClock::now() and the subsequent boundary checks would therefore accept a timestamp recorded on recovery and reused on re-pausing. The contract in net.h is the false-to-true transition, so that mistake would shorten a later pause's interval when an uncongested gap separates the episodes. Insert clock += 1min between draining and re-queuing, retaining the existing equality and timeout-boundary assertions.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
Pausing message processing when the send buffer is full avoids producing responses that cannot yet be delivered, including unnecessary disk reads and block serialization.
Historical #973 introduced stopping processing rather than immediately disconnecting on a full send buffer, explicitly identifying avoided disk and serialization work as its main advantage. At the pinned head, ProcessMessages returns when fPauseSend is set, and ProcessGetData also observes that state. The new test exercises the lifetime of this existing backpressure state, not a suspension of socket writes.
The paused-send timeout bounds how long a peer can occupy a connection slot without draining the send buffer below its threshold. Twenty minutes was chosen to match the existing ping timeout.
The predecessor #36667 explicitly describes peers on ancient versions remaining paused for a long time and calls continued slot allocation wasteful if they cannot drain below the stated 1 MB threshold. Both pinned base and head implement a separate paused-state deadline in InactivityCheck. The current PR adds deterministic coverage of that behavior without changing production networking.
Timeout policy must distinguish lack of useful progress from delayed ping responses caused by legitimate flow control and limited local bandwidth.
#36080 explains that prioritizing block responses can delay pong processing when the downloading node itself has low bandwidth. Its author explicitly treats continued block delivery as more useful than ping replies. The pinned head accordingly suspends ping timeout enforcement during block download, while retaining the separate socket and paused-send checks. This explains why these checks serve different purposes despite sharing TIMEOUT_INTERVAL.
Socket inactivity thresholds are local connection-management policy rather than a timeout mandated by a P2P BIP; older-peer compatibility has historically been balanced against usefulness and implementation simplicity.
#20651 states explicitly that the receive timeout is not specified in a P2P BIP, and justified applying 20 minutes to all peers partly by the limited usefulness of silent legacy peers and removal of version-dependent net-layer logic. This provides historical context for reusing the same interval in the pinned paused-send check, without establishing a protocol requirement for that new check.
Ralph's inferences
A deadline measured from the start of continuous backpressure prevents incidental activity from indefinitely extending a resource-holding connection.
In both pinned base and head, PushMessage and SocketSendData record m_pause_send_since only on a false-to-true pause transition. InactivityCheck evaluates it independently of m_last_send and m_last_recv. Interpreted against #36667's slot-conservation rationale, this measures sustained failure to relieve backpressure rather than total silence. The new test isolates precisely this distinction by refreshing activity timestamps while preserving the original pause time.
Source 1 · Source 2 · Source 3
Clearing the pause after sufficient draining treats congestion as recoverable; a later pause is a new episode rather than accumulated misconduct.
SocketSendData recomputes fPauseSend from queued-message plus transport memory usage. Once usage is at or below the threshold, the paused-send deadline no longer applies; a later false-to-true transition records a fresh start. This is consistent with the historical preference to tolerate temporary full buffers rather than immediately disconnect slow peers. The new test drains completely, verifies bytes were sent, and then checks a fresh interval; complete draining is stronger than the production condition needed to clear the pause.
Source 1 · Source 2 · Source 3
Unresolved disagreements
The historical record exposes a continuing tradeoff between protecting resources from many slow-reading connections and retaining legitimate low-bandwidth peers; it does not establish an optimal cutoff.
In #973, Gavin Andresen warned about an attacker filling send buffers across 100 connections from different IP addresses. Matt Corallo replied that the patch did not increase the difficulty of consuming that memory and warned that buffer-based disconnections could exclude modem users. #36667 later supplied a finite 20-minute paused-send limit for slot conservation, but the inspected discussion does not quantitatively resolve that broader calibration question. This is historical context, not a finding about the current test or production policy.