ably-java icon indicating copy to clipboard operation
ably-java copied to clipboard

Deadlock when closing library

Open paddybyers opened this issue 6 years ago • 0 comments

This is a customer problem report:

We have seen some ANRs related to ably in our Android app.

This is not a new issue but we never looked at it properly before.

This is the log:

- waiting to lock <0x0333b0a8> (a io.ably.lib.transport.ConnectionManager) held by thread 63

  at io.ably.lib.transport.ConnectionManager.requestState (ConnectionManager.java:307)
  at io.ably.lib.transport.ConnectionManager.close (ConnectionManager.java:221)
  at io.ably.lib.realtime.Connection.close (Connection.java:71)
  at io.ably.lib.realtime.AblyRealtime.close (AblyRealtime.java:70)
  at com.hubspot.android.conversations.realtime.ably.AblyRealTimeClient.close (AblyRealTimeClient.kt:83)
  at com.hubspot.android.conversations.realtime.PubSubV2ClientImpl.close (PubSubV2ClientImpl.kt:51)
  at com.hubspot.android.conversations.realtime.PubSubLifecycleObserverImpl.disconnect (PubSubLifecycleObserverImpl.kt:34)
  at com.hubspot.android.conversations.realtime.PubSubLifecycleObserverImpl_LifecycleAdapter.callMethods (PubSubLifecycleObserverImpl_LifecycleAdapter.java:33)```

> We call the close in the Android lifecycle observer (ProcessLifecycleOwner)

```@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun disconnect() {
  pubSubV2Client.close()
}```

> And this method will only call close if the connection is not closed or initialized:

```if (realtime.connection.state != ConnectionState.closed && realtime.connection.state != ConnectionState.initialized) {
  Logger.debugLog("Closing connection state: ${realtime.connection.state}")
  realtime.close()
}

Do you know what could be the issue here?

On the face of it, something is holding the ConnectionManager lock long-term. We don't know if this is somehow connected with the lifecycle event or not.

┆Issue is synchronized with this Jira Task by Unito

paddybyers avatar Apr 30 '19 11:04 paddybyers