Android/IOS + Async + TCP connections = strange behavior

Some background: moving from server/desktop to mobile development comes with surprises. One of those surprises is that Android/IOS likes to shutdown your application when the app gets backgrounded. There is no determinism in the frequency that these shutdowns occur. Thus, states must be persisted to the filesystem via files or sqlite databases.

There's a strange behavior that I've noticed when using any kind of rust crate that uses reqwest, sqlx, or any connector that relies upon TCP or TLS connections: unless these get created on a per-use basis, saving these structures in memory with the connections still in-tact can cause the async runtime to hang, blocking the entire execution. Whereas on mac/linux/windows, this never occurs, on mobile devices this seems to occur much more often. The hacky workaround appears to involve the use of a threaded-rt over a current-thread RT. However, when only a single thread is needed, adding the additional threads is wasteful on energy.

Android + Rust is somewhat of a wild west right now, but when it works, it runs beautifully. I'm putting this thread out there to see if there are others who have encountered the same issue, as well as provide for a space where future users may run in to the same problems.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.