"Communication link failure" using mysql.jdbc after my device goes to sleep mode

57 Views Asked by At

I spent several days trying to resolve an error "communication link failure" that arises exclusively after my device enters sleep mode. The error manifests when I perform an action in my app that triggers a database-related action. Strangely, if I return to my app immediately after the device wakes from sleep mode and wait between 20 to 30 seconds before executing a database-related action, the error does not occur but if I don't wait the error occur.

Notably, the error doesn't surface when my device is charging or connected to a PC via USB.

For context, I am currently working for a company and I am developing that app alone. This app is use by factory workers and I can't afford to have users wait 20 seconds every time the device goes into sleep mode.

I'm developing on Java with Android Studio using mysql-connector-java version "5.1.38", my device is also connected to a VPN using OpenVPN Connect.

I tried many things to resolve this issue:

  • close and recreate connection on OnPause and OnResume method
  • Reconnected before any database action.
  • Updated MySQL version.
  • Set USB configuration to 'charge'.

No one on the internet looks like troubleshooting the same issue. I have no idea how to solve this issue and I really need to find a solution.

0

There are 0 best solutions below