shadowsocks / shadowsocks-android

A shadowsocks client for Android
Other
35.06k stars 11.58k forks source link

VPN occasionally disconnects #2846

Closed anyuta1166 closed 2 years ago

anyuta1166 commented 2 years ago

Describe the bug VPN occasionally disconnects

To Reproduce Steps to reproduce the behavior:

  1. Just enable the VPN and after some time it occasionally disconnects

Smartphone (please complete the following information):

Configuration Put an x inside the [ ] that applies.

Additional context I've recently bought a new phone and found that Shadowsocks doesn't work as expected on it. I enable the VPN but after some time it occasionally disconnects.

I've researched the logcat and found that MIUI occasionally kills all background services, usually during the night time, despite that background usage is set to unrestricted in application settings.

01-04 23:46:14.174 W/PK      ( 5714): AutoLockOffClean in night 
01-04 23:46:14.175 I/ProcessManager( 1699): Kill reason AutoLockOffClean from pid=5714
01-04 23:46:14.177 I/ProcessManager( 1699): AutoLockOffClean: kill com.github.shadowsocks:bg Adj=100 State=5
01-04 23:46:14.177 I/ActivityManager( 1699): Killing 27121:com.github.shadowsocks:bg/u0a272 (adj 100): AutoLockOffClean
01-04 23:46:14.570 I/Zygote  (  685): Process 27121 exited due to signal 9 (Killed)
01-04 23:46:14.599 D/ProcessManager( 1699): skip restart com.github.shadowsocks:bg
01-04 23:46:14.599 I/ProcessManager( 1699): remove no clear notification:StatusBarNotification(pkg=com.github.shadowsocks user=UserHandle{0} id=1 tag=null key=0|com.github.shadowsocks|1|null|10272: Notification(channel=service-vpn pri=-2 contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x62 color=0xff607d8b category=service vis=PRIVATE))
01-04 23:46:14.600 W/ActivityManager( 1699): Scheduling restart of crashed service com.github.shadowsocks/.bg.VpnService in 90695ms
01-04 23:46:14.732 D/PowerKeeper.Vpn( 5714): removed vpn iface: tun0
01-04 23:46:14.732 D/PowerKeeper.Vpn( 5714): removed vpn: 10272
01-04 23:46:14.735 D/ConnectivityService( 1699): NetworkAgentInfo [VPN () - 112] EVENT_NETWORK_INFO_CHANGED, going from CONNECTED to DISCONNECTED
01-04 23:46:14.735 I/AppActiveChecker( 5714): uid:10272change to inactive
01-04 23:46:14.735 I/ActiveStateController( 5714): Vpn disconnect, uid is 10272
01-04 23:46:14.738 I/PowerKeeperConfigureManager( 5714): Vpn disconnect, uid is 10272
01-04 23:46:14.739 D/ConnectivityService( 1699): NetworkAgentInfo [VPN () - 112] got DISCONNECTED, was satisfying 1

It seems that this is a known MIUI feature and nothing can be done with this behavior. But another applications seems to survive through this. I guess that their workaround is to periodically check if the background service is alive and relaunch it if needed. Is it possible to add the same workaround to Shadowsocks? I guess it should be possible as there is already the auto-connect on boot feature.

dev4u commented 2 years ago

试试设置允许应用自启动。

anyuta1166 commented 2 years ago

试试设置允许应用自启动。

I didn't mention it, but I already enabled Autostart in application settings too as well as setting the background usage to unrestricted and disabling battery optimization. The difference is that without autostart, Shadowsocks is not automatically launched after reboot. But that setting doesn't affect periodic background service killing.

anyuta1166 commented 2 years ago

It seems that I've found an undocumented workaround.

foi commented 2 years ago

@anyuta1166 how you solved this issue?

anyuta1166 commented 2 years ago

@foi Settings - Apps - System app settings - Security - Boost speed - Lock apps - find Shadowsocks and enable the toggle. This way the app will not be killed by both manual and automatic cleanup. The downside is that the app will always stay in memory even if it is not used and not needed.

foi commented 2 years ago

@anyuta1166 thanks!