badaix / snapdroid

Snapcast client for Android
GNU General Public License v3.0
135 stars 26 forks source link

Snapdroid clients disconnect after ~12 hours on recent Android versions #60

Open ToxicFrog opened 11 months ago

ToxicFrog commented 11 months ago

I have (for the purposes of this bug report) two snapdroid instances: bullhead, running LineageOS 17 (Android 10) on a Nexus 5X, and sargo, running LineageOS 19 (Android 12) on a Pixel 3A.

Both are plugged in, have battery optimizations disabled for snapdroid, and have the "remain awake when plugged in" developer setting turned on.

The one on bullhead remains connected indefinitely and appears to automatically reconnect even if the snapserver is briefly inaccessible. The one on sargo, however, reliably disconnects after about 12 hours. When I go to look at it, snapdroid is still running but the status display is empty, showing no volume controls, like it can't connect to the server at all. Tapping the play/stop button causes it to immediately reconnect, however.

From the server side it looks like this (annotations added by me):

# sargo connects
Nov 06 10:24:00 ancilla snapserver[6415]: ControlServer::NewConnection: ::ffff:192.168.1.146
Nov 06 10:24:00 ancilla snapserver[6415]: Removing 1 inactive session(s), active sessions: 2
Nov 06 10:24:05 ancilla snapserver[6415]: StreamServer::NewConnection: ::ffff:192.168.1.146
Nov 06 10:24:05 ancilla snapserver[6415]: Hello from c569fde7-aa74-439c-bbf6-e8366b899e0c, host: Pixel 3a, v0.27.0, ClientName: Snapclient, OS: Android 12, Arch: arm64-v8a, Protocol version: 2

# bullhead disconnects and immediately reconnects; this is repeated several times over the course of the day
Nov 06 11:11:03 ancilla snapserver[6415]: Error reading message header of length 0: End of file
Nov 06 11:11:03 ancilla snapserver[6415]: onDisconnect: aff58ab0-e699-406f-9fac-0de359b983fd
Nov 06 11:11:04 ancilla snapserver[6415]: StreamServer::NewConnection: ::ffff:192.168.1.141
Nov 06 11:11:04 ancilla snapserver[6415]: Hello from aff58ab0-e699-406f-9fac-0de359b983fd, host: nexus, v0.24.0, ClientName: Snapclient, OS: Android 10, Arch: arm64-v8a, Protocol version: 2

# sargo disconnects and remains disconnected until the following morning, when I manually reconnect it
Nov 06 22:49:45 ancilla snapserver[6415]: Error reading message header of length 0: End of file
Nov 06 22:49:45 ancilla snapserver[6415]: onDisconnect: c569fde7-aa74-439c-bbf6-e8366b899e0c
Nov 06 22:49:45 ancilla snapserver[6415]: Removing 1 inactive session(s), active sessions: 2

I have also previously observed this in Android 11, on a tablet, but the device suffered a hardware failure and is no longer around for testing.

Since they're all running the same version of Snapdroid, it seems plausible that this is a change in how Android 11+ handles long-running processes. I'm not sure if the fix is:

I am, however, confident that it should be fixable, on the basis that I have other long-running, network-connected programs on android 12, like weechat, that remain connected long-term.

boredomwontgetus commented 9 months ago

Can confirm! I see exactly the same behavior after ~12h.