Skip to content

Possible TCP socket leak and useless keepalive #94

@lixin9311

Description

@lixin9311

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions