Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in my app #67

Closed
UrielFrankel opened this issue Oct 4, 2023 · 6 comments
Closed

Crash in my app #67

UrielFrankel opened this issue Oct 4, 2023 · 6 comments

Comments

@UrielFrankel
Copy link

UrielFrankel commented Oct 4, 2023

Here is the stack trace:

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@651c9a5[Not completed] rejected from java.util.concurrent.ThreadPoolExecutor@6e1517a[Shutting down, pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 1]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2072)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:834)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1364)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
	at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:671)
	at io.github.centrifugal.centrifuge.Client$1.onClosed(SourceFile:15)
	at okhttp3.internal.ws.RealWebSocket.writeOneFrame$okhttp(SourceFile:188)
	at okhttp3.internal.ws.RealWebSocket$WriterTask.runOnce(SourceFile:3)
	at okhttp3.internal.concurrent.TaskRunner.runTask(SourceFile:63)
	at okhttp3.internal.concurrent.TaskRunner.access$runTask(Unknown Source:0)
	at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(SourceFile:55)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
	at java.lang.Thread.run(Thread.java:1012)

I have zero clue what happen. As you can see I can't even guard it with try/catch. I called unsubscribe() and then close(). Is that the problem? Should I put the close() in the onDestroy of the App? thanks.

@FZambia
Copy link
Member

FZambia commented Oct 4, 2023

Hello @UrielFrankel - seems that you can easily reproduce this? Can you provide example code?

@UrielFrankel
Copy link
Author

UrielFrankel commented Oct 5, 2023

I can't reproduce it but I can send you what I do:

fun disconnect() {
    unsubscribe()
    Logger.d(TAG, "disconnect() called")
    try {
        client?.close(5000) // from demo app
        client = null
    } catch (e: InterruptedException) {
        Logger.e(TAG, "error in centrifugo disconnection ", e)
    }
    this.connectionId = null
}

fun unsubscribe() {
    Logger.d(TAG, "unsubscribe() called")
    currentSubscription?.let {
        client?.removeSubscription(it)
        currentSubscription = null
    }
}

I suspect that calling removeSubscription and immediately close is the problem.

@FZambia
Copy link
Member

FZambia commented Oct 5, 2023

Thanks, I'll experiment - in general you need to call Close when you don't need client anymore. After calling Close client is unusable.

But in this case I suppose onClosed callback of WebSocket is called after ThreadPoolExecutor already closed. We already handle RejectedExecutionException in OnFailure -

} catch (RejectedExecutionException ignored) {
, but for some reason not handling it in other WebSocket callbacks - like the one in your stacktrace (onClosed).

@UrielFrankel
Copy link
Author

Good news, I was able to reproduce it in my app. I called for close before i was fully connected and close calls disconnect.

@FZambia
Copy link
Member

FZambia commented Oct 8, 2023

Reproduced locally and opened #71

@FZambia
Copy link
Member

FZambia commented Oct 10, 2023

The fix is shipped in 0.3.1

@FZambia FZambia closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants