Windows – TCP timeout for established connections in Windows

tcptcpipwindows

I have the following situation:

  • Application (Firebird DB client) on a client computer opens a TCP connection to server on port 3050
  • Application crash on client, application terminated
  • netstat on the server still shows TCP-connection ESTABLISHED on port 3050 to clients ip address.
  • powered off client
  • netstat on the server still shows TCP-connection ESTABLISHED on port 3050 to clients ip address.
  • waited several minutes
  • netstat on the server still shows TCP-connection ESTABLISHED on port 3050 to clients ip address.

Is there a timeout for established connections under Windows (Win8.1 in this case)?
Can I change this timeout?

I found this, but this does not seem to answer my question for established connections.

Best Answer

By default an established TCP connection does not time out (but may do so because of hardware restrictions).

An application can use the TCP keepalive mechanism to check for broken connections. In Firebird (>1.5) TCP keepalives are enabled.

The keepalive "timeout" has to be set on the server. The default TCP keepalive time interval in Windows is 2 hours (but recommended are 5 minutes). It can be set in the HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\KeepAliveTime registry key.

More details from above links:

a failed client connection will be closed after the following time interval: KEEPALIVE_TIME+ ( KEEPALIVE_PROBES+1)* KEEPALIVE_INTERVAL

With following corresponding registry values in Windows:

KEEPALIVE_TIME = KeepAliveTime (default: 7200 seconds)
KEEPALIVE_INTERVAL = KeepAliveInterval (default: 1 second)
KEEPALIVE_PROBES = TCPMaxDataRetransmissions (default: 5)

But:

A keepalive segment is sent every two hours by default [...]. Even if enabled, other upper-layer protocols such as NetBIOS send their own keepalive value. If the keepalive interval that the upper-layer protocol uses is less than the TCP keepalive interval, TCP keepalive value is never sent. For example, NetBIOS sessions over TCP/IP send a NetBIOS keepalive request every 60 minutes. Therefore, TCP keepalive values that are enabled for a NetBIOS session are never used.

Related Topic