TCP Server - RST,ACK (Debian Linux)

Hello.
I'm have a problem with TCP Server (tokio::net::TcpListener - Rust).
Server send packet with RST,ACK flag to tcp client - periodic ~120 sec. And establishes a new session.

Why is this happening? Can I set it up somehow?

let done = listener.incoming().map_err(
   move |e| { /* log error */}).for_each(move |socket| {

   socket.set_nodelay(true).expect("Cannot set no delay option.");
   let dur = Duration::from_secs(300);
   socket.set_keepalive(Some(dur)).expect("Cannot set keepalive option.");
   socket.set_linger(Some(dur)).expect("Cannot set keepalive option.");
   socket.set_ttl(250).expect("set_ttl failed");

    let processor = tcp_reader.for_each(
      move |bytes|{
           /* Process */ 
      }).and_then(move |()| {
          Ok(())
      }).or_else(move |err| {
          Err(err)
      }).then(move |result| {
          Ok(())
      });

      tokio::spawn(processor)
});

Wireshark dump file - modbus_rst_ack_problem.pcapng

You need to give more details. I will note that you're linking to outdated Tokio documentation.

It might be some sort of timeout.

If you are leaving a connection open and idle for a long time, has the client been configured to send keepalive packets (tokio::net::TcpStream::set_keepalive())?

Yes.

let dur = Duration::from_secs(1000);
socket.set_keepalive(Some(dur)).expect("Cannot set keepalive option.");
$ cat /proc/sys/net/ipv4/tcp_keepalive_time 
7200

Have you tried decreasing your keepalive interval? You're sending a keepalive every 1000 seconds, but the connection times out after only 100 seconds.

1 Like

Yes. Has no effect.
The server sends RST, ACK every 120 seconds.

PS. How to get TCP Header from TcpStream?

You can't.

A TcpStream is an abstraction over TCP that provides you with a stream of bytes, so it tries to hide things like the existence of TCP packets and headers. Most TcpStream types will deliberately only expose functions for reading/writing data, and maybe a couple simple knobs like timeouts or keep-alives.

If you want access to the TCP headers then you'd need to use a different TCP library. Maybe something that lets you work with raw sockets from the OS and gives you fine-grained access like pnet.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.