Search code examples
bashtcpconnection-timeout

How to decrease TCP connect() system call timeout?


In command below I enable file /dev/tcp/10.10.10.1/80 both for reading and writing and associate it with file descriptor 3:

$ time exec 3<>/dev/tcp/10.10.10.1/80
bash: connect: Operation timed out
bash: /dev/tcp/10.10.10.1/80: Operation timed out

real    1m15.151s
user    0m0.000s
sys     0m0.000s

This automatically tries to perform TCP three-way handshake. If 10.10.10.1 is not reachable as in example above, then connect system call tries to connect for 75 seconds. Is this 75 second timeout determined by bash? Or is this system default? Last but not least, is there a way to decrease this timeout value?


Solution

  • It is determined by TCP. It can be decreased on a per-socket basis by application code.

    NB The timeout only takes effect if there is no response at all. If there is a connection refusal, the error occurs immediately.