freenet-core icon indicating copy to clipboard operation
freenet-core copied to clipboard

Keep-alive packets received but connections still timeout after 30 seconds

Open sanity opened this issue 5 months ago • 0 comments

Problem

Gateway connections timeout after exactly 30 seconds despite keep-alive packets being sent and received every 10 seconds.

Observed Behavior

  1. Client establishes connection to gateway successfully
  2. Client sends NoOp keep-alive packets every 10 seconds (confirmed via trace logs)
  3. Gateway sends 44-byte packets (likely NoOp) to client every 10 seconds (confirmed via trace logs)
  4. 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_received is only updated when packet received from channel
  • Line 564: Timeout check that triggers ConnectionClosed

Hypothesis

The keep-alive packets may be:

  1. Getting stuck in the channel between connection_handler and PeerConnection
  2. Being processed but not updating last_received
  3. 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

sanity avatar Jun 15 '25 18:06 sanity