Application crashes: issue related to socket connection

My app crashes in this case:

  1. start app, pres home, lock phone
  2. unlock phone, lunch app - app crashes with next error log:

IOSApplication 3 paused
2016-12-02 16:14:53.698106 MyApp[588:106537] [] nw_socket_get_input_frames recvmsg(fd 28, 1024 bytes): [57] Socket is not connected
2016-12-02 16:14:53.699505 MyApp[588:106537] [] nw_socket_get_input_frames recvmsg(fd 29, 1024 bytes): [57] Socket is not connected
2016-12-02 16:14:53.723170 MyApp[588:106713] [] nw_connection_write_close 12 Connection is not ready, sending error callback
applicationWillTerminate
2016-12-02 16:14:53.758127 MyApp[588:106713] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [57] Socket is not connected
2016-12-02 16:14:53.778602 MyApp[588:106723] [] nw_connection_write_close 13 Connection is not ready, sending error callback
2016-12-02 16:14:53.780547 MyApp[588:106723] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [57] Socket is not connected

Looks like some error ocures somewhere in moe/native code and my exception handler doesn’t work.
I use next code for handling errors but it doesn’t work with this issue((

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override public void uncaughtException(Thread t, Throwable e) {
System.out.println("Exception: " + e + " Thread: " + t);
}
});

In case you turn your device on “in airplane” mode while app running - works well.
Could you please help me to find a root cause?

Dear Oleg_Bondar,

could you please share a project with us where we can reproduce this issue?

Best Regards,
Kristóf

Unfortunately I can’t share the app because of NDA.
I found workaround by closing connection when leave the app. And trying to reconnect when resume app.
Overriding pause() and resume() methods in libgdx ApplicationAdapter class:

@Override
public void pause () {
//close connection
}

@Override
public void resume () {
//reconnect
}

Hi Oleg,

on iOS an app can only function in the background in a small number of predefined use cases. Therefore it is a good practice to close all open connections prior to going into the background, unless it is absolutely needed (e.g. your app needs to play music from the network while it is in the background - in which case it needs to specify that it will play music / use network in the background.

Best Regards,
Gergely

1 Like

Hi,

I’m facing the same issue (see my post here) with Retrofit. I don’t have a stack trace so I can’t be sure it’s 100% related, but do you know if I can somehow manage to close any Retrofit connection when the app goes in background?