Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TCP KeepAlive by default #546

Closed
zonyitoo opened this issue Jun 5, 2021 · 11 comments
Closed

Enable TCP KeepAlive by default #546

zonyitoo opened this issue Jun 5, 2021 · 11 comments
Assignees

Comments

@zonyitoo
Copy link
Collaborator

zonyitoo commented Jun 5, 2021

ref #490

TCP Keep Alive is useful for purging dead connections. Since many users run shadowsocks with mobile connection, there should be higher chance to leave dead connections on servers.

Further more, Go already have set 15 seconds keep alive timeout on all TCP connections. (Go's source code can prove that: net/tcpsock_posix.go:accept. And here is the issue golang/go#31510 that introduced this feature into the standard net library.)

SO_KEEPALIVE is not enabled by default for most operating systems.

Introducing this feature shouldn't break anything. If you have encountered anything related to this, please comment.

Adding a new configuration field for customizing the keep alive timeout

{
    "keep_alive": 15
}
@zonyitoo zonyitoo self-assigned this Jun 5, 2021
@om2mo
Copy link

om2mo commented Jun 6, 2021

15秒可能消耗过多的电量在移动平台设备,如何在命令行中配置它?

zonyitoo added a commit that referenced this issue Jun 6, 2021
@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 6, 2021

Try with this commit and specify keep alive timeouts with command line options like --tcp-keep-alive 300.

@om2mo
Copy link

om2mo commented Jun 6, 2021

➜ ~ sslocal -U --protocol redir --tcp-fast-open --tcp-no-delay --tcp-keep-alive 300 -s server -m aes-256-gcm -k -b 0.0.0.0:12345
error: Found argument '--tcp-keep-alive' which wasn't expected, or isn't valid in this context
Did you mean --tcp-redir?

@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 6, 2021

You should either compile from the latest master branch, or download the nightly build of v1.11.2.

@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 7, 2021

@madeye @Mygod Consider adding --tcp-keep-alive or keep_alive configuration if shadowsocks-android upgrades the underlying shadowsocks-rust, if this related to battery consumption.

But v2ray-plugin will still have the default 15 seconds set by Go's net library.

@Mygod
Copy link
Contributor

Mygod commented Jun 7, 2021

According to this, Android will not respect TCP keep alive settings when device goes to sleep.

@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 7, 2021

So, @om2mo your assumption doesn't exist. What's your mobile platform?

@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 7, 2021

But on the other hand, what if system is not going to sleep? Would this increase battery consumption while system is awake?

@Mygod
Copy link
Contributor

Mygod commented Jun 7, 2021

Setting it to 28 minutes as default should alleviate he problem.

@zonyitoo
Copy link
Collaborator Author

zonyitoo commented Jun 7, 2021

Why 28 minutes?

@Mygod
Copy link
Contributor

Mygod commented Jun 7, 2021

It is the timeout for GMS heartbeat on mobile network.

@pexcn pexcn mentioned this issue Jun 17, 2021
29 tasks
atkdef pushed a commit to atkdef/shadowsocks-rust that referenced this issue Sep 24, 2021
atkdef pushed a commit to atkdef/shadowsocks-rust that referenced this issue Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants