freenet-core
freenet-core copied to clipboard
Keep-alive packets received but connections still timeout after 30 seconds
Problem
Gateway connections timeout after exactly 30 seconds despite keep-alive packets being sent and received every 10 seconds.
Observed Behavior
- Client establishes connection to gateway successfully
- Client sends NoOp keep-alive packets every 10 seconds (confirmed via trace logs)
- Gateway sends 44-byte packets (likely NoOp) to client every 10 seconds (confirmed via trace logs)
- Connection times out exactly 30 seconds after establishment
Root Cause Analysis
The issue appears to be that keep-alive packets are received at the transport layer (connection_handler) but may not be updating the last_received timestamp in PeerConnection::recv().
Evidence from logs:
- Connection established:
18:17:37 - Keep-alive sent:
18:17:47,18:17:57,18:18:07 - Keep-alive received:
18:17:47,18:17:57,18:18:07 - Connection dropped:
18:18:07(exactly 30 seconds later)
Code Location
crates/core/src/transport/peer_connection.rs:
- Line 291:
KILL_CONNECTION_AFTER = Duration::from_secs(30) - Line 304:
last_receivedis only updated when packet received from channel - Line 564: Timeout check that triggers ConnectionClosed
Hypothesis
The keep-alive packets may be:
- Getting stuck in the channel between connection_handler and PeerConnection
- Being processed but not updating
last_received - Being dropped somewhere in the pipeline
Impact
This prevents nodes from maintaining stable connections to gateways, causing:
- Constant reconnection attempts
- No ring connections found errors for operations
- River chat and other apps unable to function