Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 773
Jingguo Yao Avatar asked Aug 15 '17 13:08

Jingguo Yao


1 Answers

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.

like image 167
Steffen Ullrich Avatar answered Sep 22 '22 10:09

Steffen Ullrich