outline-ss-server icon indicating copy to clipboard operation
outline-ss-server copied to clipboard

Option to modify TCP Keep-Alive duration in Client (in the form of a battery life optimization setting)

Open ValdikSS opened this issue 3 years ago • 5 comments

https://github.com/shadowsocks/go-shadowsocks2/issues/224 Since outline-ss-server is based on go-shadowsocks2, this issue applies to it as well.

Describe the bug go-shadowsocks2 sends TCP Keep-Alive packets every 15 seconds, on every connected and listened TCP socket (shadowsocks server-client connections, outgoing connections to other servers), which leads to high battery usage on mobile devices.

Since keep-alive interval is set also on listening socket, non-go-shadowsocks2 clients will also receive keep-alive packets every 15 seconds when connecting to go-shadowsocks2 server.

More information here: https://github.com/golang/go/issues/48622

To Reproduce Steps to reproduce the behavior:

  1. Connect to go-shadowsocks2 server or run go-shadowsocks2 client.
  2. Initiate TCP connection and keep it idle for some time.
  3. Check keep-alive packets sending/receiving every 15 seconds with the network sniffer.

Expected behavior I expect Keep-Alive interval to be configurable.
go-shadowsocks2 should allow to increase TCP Keep-Alive or to disable it completely.
15 seconds is a golang default value and it's way too short. For comparison, Linux sets default keep-alive value to 2 hours (which is probably too high).

ValdikSS avatar Dec 23 '21 01:12 ValdikSS

you can build the framework by yourself

David699 avatar Sep 19 '22 09:09 David699

you can build the framework by yourself

Sure I can, but that won't fix high battery drain for all other users.

ValdikSS avatar Sep 30 '22 05:09 ValdikSS

Thanks for reporting that @ValdikSS.

We've had significant issues in the past due to the server closing idle connections and the lack of a keep-alive. See https://github.com/Jigsaw-Code/outline-server/issues/85

It's not clear what the values should be, and we need to figure that out. It seems we can tweak both the server and the client. My issue with the config is that no one except a few will have any idea what to do with it, so we will make the app more complex while not really helping the bulk of our user base.

How can we address that?

fortuna avatar Oct 24 '23 18:10 fortuna

@fortuna, this issue is about TCP-level Keep-Alive in golang, not a software-level connection timeout found in shadowsocks-libev.

All current golang applications which use dial use 15-second TCP keep-alive, which drains battery.

ValdikSS avatar Oct 24 '23 22:10 ValdikSS

We need more fined grained controls to adjust this. A longer initial interval, followed by quicker probes.

ValdikSS has an issue reported on Go, which got fixed on Go 1.23.

We can wait for Go 1.23 to add it to the server, or we can implement it ourselves with socket flags. We have already disabled Keep-Alives in the Client, which should help.

fortuna avatar Apr 25 '24 17:04 fortuna