Skip to content

Support configurable TCP socket options (TCP_USER_TIMEOUT) #197

@Karrq

Description

@Karrq

Problem

When using TcpTls (or plain Tcp) under network conditions with packet loss, TCP's default retransmission behavior causes unbounded delivery delays. The default TCP_RETRIES2 (15 retries) means TCP will keep retransmitting for up to ~13-30 minutes before giving up, while the connection appears healthy from the application's perspective.

Currently, the only socket option set is TCP_NODELAY (in both tcp/mod.rs and tcp_tls/mod.rs connect() and poll_accept()). There's no way for consumers to configure retransmission behavior.

This is problematic for applications that implement their own reliability/recovery layer on top of msg-rs - TCP's silent retransmissions become redundant and introduce unbounded latency that the application can't control or detect.

Proposed solution

Add socket-level configuration to the Tcp and TcpTls client/server configs. At minimum:

  • TCP_USER_TIMEOUT (Linux) - max time (ms) unacknowledged data can remain before TCP aborts the connection. This is the most impactful option for bounding retransmission delays.

These would be applied in connect() and poll_accept() right alongside the existing set_nodelay(true) call:

let stream = TcpStream::connect(addr).await?;
stream.set_nodelay(true)?;

#[cfg(target_os = "linux")]
if let Some(timeout) = config.user_timeout {
    // setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, timeout_ms)
}

Nice-to-haves (follow-up)

  • SO_KEEPALIVE + TCP_KEEPIDLE / TCP_KEEPINTVL for faster dead connection detection
  • Exposing these through the Control channel for runtime tuning (note: SubDriver doesn't currently wire up control_rx, so this would also need work in msg-socket)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions