Skip to content

Coroutines: Channel.offer can still be called after channel has been closed. #1585

Closed
@EtienneTheScore

Description

@EtienneTheScore

Hi!

We use a wrapper around ApolloSubscriptionCall<T>.toChannel extension and we're having some crashes although we use it inside a CoroutineScope with an exception handler.

Error:

com.apollographql.apollo.internal.subscription.ApolloSubscriptionTerminatedException: 
  at com.myapp.extensions.ApolloExtensionsKt$toChannelHandleTerminate$2.onTerminated (ApolloExtensions.kt:39)
  at com.apollographql.apollo.internal.RealApolloSubscriptionCall$SubscriptionManagerCallback.onTerminated (RealApolloSubscriptionCall.java:168)
  at com.apollographql.apollo.internal.subscription.RealSubscriptionManager.onConnectionClosed (RealSubscriptionManager.java:284)
  at com.apollographql.apollo.internal.subscription.RealSubscriptionManager$SubscriptionTransportCallback$4.run (RealSubscriptionManager.java:457)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:764)

After investigation, we found that this is caused by some concurrency issues inside ApolloSubscriptionCall.Callback.

The method channel.offer(response) can still be called after the channel has been closed. And since the callback use a separate Thread, the exception isn't caught by the coroutine's exception handler, causing a crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions