Perspective client disconnections?

I’m seeing a strange issue where perspective sessions running on a mobile device unexpectedly terminate after some time. More precisely, the gateway periodically uses system.perspective.sendMessage to request information from the device, and the client uses system.util.sendMessage to send a message to the gateway, where a message handler processes it (and logs a line). This mostly works, even with the phone screen off. After some time the gateway stops receiving messages, and looking at the client (turning the screen on) briefly shows a red “lost connection to gateway” message, the perspective app immediately restarts (by itself) and data start flowing again. This usually happens after a while, let’s say not before 30 minutes, but eventually happens.
I initially thought of a 4G issue with the phone, but then I kept a continuous ping to the gateway running alongside the perspective app, and tcpdump shows that while communication with the gateway (tcp port 8088) at some point stops, the ping packets keep going, so it looks like 4G connectivity is ok. Moreover, I keep the phone in the same position on the table all the time, so it’s not a mobility issue either.
Also what I find strange is that, even if it were a connectivity problem, the app itself can’t recover from the “lost connection to gateway” and I must unlock the screen to kick off the recovery process.
The phone is running Android 10 (but the exact same behavior happened with Android 8.1 and 9).

I recall some discusssions of mobile OS behavior and their battery saver algorithms that make it extremely unlikely you’ll get a screen-off phone to stay connected. Keep in mind that your “client” message handler script (target of system.perspective.sendMessage) that uses system.util.sendMessage is actually running in the gateway, too. (Jython doesn’t run in web browsers or browser-like apps.)

Sure, but why does the other data connection (ping) keep working? And why can’t the perspective client recover by itself without me unlocking the screen?
Even if everything is running in the gateway, I do see traffic from the phone to the gateway port 8088 and viceversa (while it works, of course, then it stops), so there must be at least something that involves internet traffic.
And, if everything is running in the gateway, that’s one more reason why it shouldn’t stop working, isn’t it?

I repeated the tests with battery optimizations disabled both at the global level and at the ignition app level, and I got exactly the same behavior.

FWIW we’re starting to see this behavior as well. Although we’ve more or less given up any hope of getting the perspective app to behave, we’d be interested to know in case you find a solution.

It’s now April of 2022. Did this issue every get resolved?