shadowsocks-android icon indicating copy to clipboard operation
shadowsocks-android copied to clipboard

"autoexpire" does not seem to help solve the connection loss problem of kcptun

Open faketrader opened this issue 10 years ago • 23 comments

When the kcptun is disabled, everything is OK. Different from issue #801, connections will lose only if the device is put into sleep for a while. The client parameter is -key XXX -autoexpire 60. Logs on server are as follows:

[ERR] yamux: keepalive failed: i/o deadline reached
[ERR] yamux: Failed to read header: broken pipe
keepalive timeout

Simply push the Reset button in the app will solve the problem. Meanwhile, it works fine on windows client. So I believe there is nothing to do with the server. Here is a table to better describes the issue:

Setup When the device is inuse After wakeup from sleep On Windows
shadowsock OK OK OK
shadowsock + kcptun OK lose connection OK

Device info.: Samsung Galaxy Note 3, Android 5.0 root. Shadowsocks works in VPN mode.

faketrader avatar Aug 27 '16 05:08 faketrader

It's expected that yamux would report timeout. When the connection loss happen, could you visit any sites on your device?

madeye avatar Aug 27 '16 06:08 madeye

Also, please try smaller numbers of autoexpire, e.g 5.

madeye avatar Aug 27 '16 06:08 madeye

I have bypass LAN & China enabled. When connection loses, I can still visit websites located in China, but I cannot open foreign websites.

I will try smaller number to see what happens, but I am concerned that it may cause battery drain.

faketrader avatar Aug 27 '16 08:08 faketrader

It won't cause any battery drain. Actually, it may help to solve some battery drain related issues.

If you still see conntion loss after setting that number smaller than 5, then it's nothing to do with kcptun. Double check that the kcptun process isn't killed by any background service killer. This process is likely being killed by some agressive process managers, as it sends keep-alive packets frequently.

madeye avatar Aug 27 '16 08:08 madeye

I've been testing this feature for 1 hr and no connection loss observed so far. :-)

Mygod avatar Aug 27 '16 17:08 Mygod

Update: It turns out that I forgot to turn on kcp last time. Just experienced connection loss and it didn't reconnect in 60s.

Mygod avatar Aug 28 '16 04:08 Mygod

When the connection lost, what's the CPU% of kcptun? Is it 100%? Or a large number like ~20%?

madeye avatar Aug 28 '16 04:08 madeye

As I've enabled log for kcptun, could you try again and capture your log when connection lost?

adb logcat -s kcptun

madeye avatar Aug 28 '16 04:08 madeye

OK. Reopen?

Mygod avatar Aug 28 '16 04:08 Mygod

Forgot to do a manual reset. So no log dump.

However here's an interesting find: kcptun process is killed. Trying to run again...

Mygod avatar Aug 28 '16 06:08 Mygod

I think this issue may be caused by a stupid bug that the stdout/stderr buffer becomes full for kcptun...

After redirect the log to logcat, I cannot detect connection loss any more. 😅

madeye avatar Aug 28 '16 09:08 madeye

Hmm if that turns out to be the case, maybe we should just let kcptun flood logcat?

Mygod avatar Aug 28 '16 09:08 Mygod

Already fixed here: https://github.com/shadowsocks/kcptun/commit/c4054b07a6b493f48d4e9c35c6c1a4a047462325

madeye avatar Aug 28 '16 09:08 madeye

Ok. Just then my connection is super unstable (frequent mobile data switching). I wonder if that's causing kcptun not running. I'll test it again later.

Mygod avatar Aug 28 '16 10:08 Mygod

I just pulled the latest commit (updated submodules, did a reset) and I'm not seeing anything on my logcat except ShadowsocksVpnService and GuardedProcess. Is this normal?

Mygod avatar Aug 28 '16 14:08 Mygod

Could you see stream open/close with tag kcptun?

madeye avatar Aug 28 '16 14:08 madeye

No. :confused:

Mygod avatar Aug 28 '16 14:08 Mygod

Oh, did a clean and build again and it worked. Never mind...

Mygod avatar Aug 28 '16 14:08 Mygod

Ok I experienced a connection loss twice just now and it reconnected after a while. From logcat I noticed that the session actually auto expire after 2 ~ 3 mins instead of the default 60 seconds. (network active during this time) Is this normal?

Mygod avatar Aug 28 '16 16:08 Mygod

60s is the minimum time to expire a yamux session. So, it could be 2 or 3 mins, which depends on if there are new tcp connections created from shadowsocks.

Could you try a smaller number of autoexpire? For example, 10 seconds?

madeye avatar Aug 29 '16 00:08 madeye