Jingguo Yao
Jingguo Yao

Reputation: 7986

How long can a TCP connection stay open?

Consider such a scenario, there are client-a and server-b. server-b has TCP keepalive disabled. And server-b does not have any application logic to check whether a TCP connection is open. client-a establishes a TCP connection to server-b. There is no data transfer between client-a and server-b afterward. In such a case, will the server ever close the idle connection? Or the server will have the TCP connection stay open forever.

After reading Longest Open TCP Connection?, I guess that such a TCP connection will stay open forever. Is my guess correct?

Upvotes: 20

Views: 12519

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123320

There is no limit in the TCP connection itself. Client and server could in theory stay connected for years without exchanging any data and without any packet flow. Problems are usually caused by middleboxes like NAT router or firewalls which keep a state and expire the state after some inactivity. Any new packets sent within the connection cannot be delivered then because no associated state exists anymore in the middlebox.

Upvotes: 34

Related Questions