-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
In https://github.com/shadowsocks/go-shadowsocks2/blob/master/tcp.go#L142 ,
the io.Copy
will always block until an error occurs, there is no default timeout configuration for TCP sockets, so the socket will be kept open unless the remote server (Google.com) or local application (Chrome) closes the socket. AFAIK, they usually keep the connection open for several minutes, and if the proxy fails to receive the FIN packet, the socket will be kept, until a keepalive packet is lost (there gonna be another issue).
When dealing with a large number of clients and connections, the socket number may be exhausted.
I think we should set the deadline and close the connection if timeout.
I can issue a PR if you agree.
And the default keepalive interval on most systems is 7200s, that means if the proxy fails to receive a FIN packet, hopefully, after 2hr the socket will be closed. It's useless to set SO_KEEPALIVE
alone.
Again, set a timeout on the proxy side can solve all these problems.
$ sysctl -n net.ipv4.tcp_keepalive_time
7200