Tcp default timeout linux

TCP Socket no connection timeout

I open a TCP socket and connect it to another socket somewhere else on the network. I can then successfully send and receive data. I have a timer that sends something to the socket every second. I then rudely interrupt the connection by forcibly losing the connection (pulling out the Ethernet cable in this case). My socket is still reporting that it is successfully writing data out every second. This continues for approximately 1hour and 30 minutes, where a write error is eventually given. What specifies this time-out where a socket finally accepts the other end has disappeared? Is it the OS (Ubuntu 11.04), is it from the TCP/IP specification, or is it a socket configuration option?

3 Answers 3

Pulling the network cable will not break a TCP connection(1) though it will disrupt communications. You can plug the cable back in and once IP connectivity is established, all back-data will move. This is what makes TCP reliable, even on cellular networks.

When TCP sends data, it expects an ACK in reply. If none comes within some amount of time, it re-transmits the data and waits again. The time it waits between transmissions generally increases exponentially.

After some number of retransmissions or some amount of total time with no ACK, TCP will consider the connection «broken». How many times or how long depends on your OS and its configuration but it typically times-out on the order of many minutes.

 tcp_retries2 (integer; default: 15; since Linux 2.2) The maximum number of times a TCP packet is retransmitted in established state before giving up. The default value is 15, which corresponds to a duration of approximately between 13 to 30 minutes, depending on the retransmission timeout. The RFC 1122 specified minimum limit of 100 seconds is typically deemed too short. 

This is likely the value you’ll want to adjust to change how long it takes to detect if your connection has vanished.

Читайте также:  Проверить включена ли виртуализация linux

(1) There are exceptions to this. The operating system, upon noticing a cable being removed, could notify upper layers that all connections should be considered «broken».

Источник

Change the TCP timeout for a linux network device [closed]

I am programming linux device driver over a very slow interface, whose ping round time can be as long as several minutes. When I try to use TCP to establish connection between two nodes the connection always times out. Is there a method to set the TCP retransmission or handshaking timeout longer in the driver, or are there any commands to set it with? Thanks

2 Answers 2

Have you tried searching for an answer to this question? A quick Google search gave me this, which appears to directly address this issue. The summary is that the setting of the net.ipv4.tcp_syn_retries determines that maximum timeout available to TCP connections.

If that document doesn’t answer your question, you should indicate what you tried and how the behavior differed from what you expected.

/proc/sys/net/ipv4/tcp_retries1 /proc/sys/net/ipv4/tcp_retries2 
tcp_retries1 - INTEGER This value influences the time, after which TCP decides, that something is wrong due to unacknowledged RTO retransmissions, and reports this suspicion to the network layer. See tcp_retries2 for more details. RFC 1122 recommends at least 3 retransmissions, which is the default. tcp_retries2 - INTEGER This value influences the timeout of an alive TCP connection, when RTO retransmissions remain unacknowledged. Given a value of N, a hypothetical TCP connection following exponential backoff with an initial RTO of TCP_RTO_MIN would retransmit N times before killing the connection at the (N+1)th RTO. The default value of 15 yields a hypothetical timeout of 924.6 seconds and is a lower bound for the effective timeout. TCP will effectively time out at the first RTO which exceeds the hypothetical timeout. RFC 1122 recommends at least 100 seconds for the timeout, which corresponds to a value of at least 8. 

Источник

Оцените статью
Adblock
detector