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: Websocket Illegal State Exception #3338

Closed
dshokouhi opened this issue Feb 15, 2023 · 6 comments
Closed

Crash: Websocket Illegal State Exception #3338

dshokouhi opened this issue Feb 15, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@dshokouhi
Copy link
Member

Home Assistant Android app version(s):

First appeared beta-2762-93844ffe-full, still impacting 2023.1.1

Android version(s):

All supported versions 5-13

Device model(s):

Numerous - almost 7.5k users impacted

Home Assistant version:

unknown

Last working Home Assistant release (if known):

unknown

Description of problem, include YAML if issue is related to notifications:

I am unsure what causes this issue but it is second from the top in our crash list

Companion App Logs:

Log from 2023.1.1

Exception java.lang.IllegalStateException:
  at kotlinx.coroutines.CancellableContinuationImpl.alreadyResumedError (CancellableContinuationImpl.kt:482)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl (CancellableContinuationImpl.kt:447)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default (CancellableContinuationImpl.kt:420)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeWith (CancellableContinuationImpl.kt:328)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.handleMessage (WebSocketRepositoryImpl.kt:510)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.access$handleMessage (WebSocketRepositoryImpl.kt:70)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl$onMessage$1$1.invokeSuspend (WebSocketRepositoryImpl.kt:653)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at kotlinx.coroutines.internal.LimitedDispatcher.run (LimitedDispatcher.kt:42)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:95)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:570)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:750)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:677)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:664)

Screenshot or video of problem:

Additional information:

@dshokouhi dshokouhi added the bug Something isn't working label Feb 15, 2023
@Pepeanuts
Copy link

What is the problem of this issue ?
I've some long loading when HA's apps start and navigate into apps.
Screenshot_20230220-193949

@dshokouhi
Copy link
Member Author

What is the problem of this issue ?

please go to settings > companion app from this pop-up then go to Show and share logs and look to see if your error matches this error. If it does not you will need to create a new issue with the error log.

@dshokouhi
Copy link
Member Author

Crash is still occurring in beta 3252

Exception java.lang.IllegalStateException:
  at kotlinx.coroutines.CancellableContinuationImpl.alreadyResumedError (CancellableContinuationImpl.kt:482)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl (CancellableContinuationImpl.kt:447)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default (CancellableContinuationImpl.kt:420)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeWith (CancellableContinuationImpl.kt:328)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.handleMessage (WebSocketRepositoryImpl.kt:567)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.access$handleMessage (WebSocketRepositoryImpl.kt:73)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl$onMessage$1$1.invokeSuspend (WebSocketRepositoryImpl.kt:715)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at kotlinx.coroutines.internal.LimitedDispatcher.run (LimitedDispatcher.kt:42)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:95)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:570)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:750)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:677)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:664)

@dshokouhi
Copy link
Member Author

Log from beta 3258

Exception java.lang.IllegalStateException:
  at kotlinx.coroutines.CancellableContinuationImpl.alreadyResumedError (CancellableContinuationImpl.kt:482)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl (CancellableContinuationImpl.kt:447)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default (CancellableContinuationImpl.kt:420)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeWith (CancellableContinuationImpl.kt:328)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.handleMessage (WebSocketRepositoryImpl.kt:600)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.access$handleMessage (WebSocketRepositoryImpl.kt:75)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl$onMessage$1$1.invokeSuspend (WebSocketRepositoryImpl.kt:748)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at kotlinx.coroutines.internal.LimitedDispatcher.run (LimitedDispatcher.kt:42)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:95)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:570)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:750)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:677)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:664)

@dshokouhi
Copy link
Member Author

Beta 10158

Exception java.lang.IllegalStateException:
  at kotlinx.coroutines.CancellableContinuationImpl.alreadyResumedError (CancellableContinuationImpl.kt:559)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl (CancellableContinuationImpl.kt:524)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default (CancellableContinuationImpl.kt:497)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeWith (CancellableContinuationImpl.kt:368)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.handleMessage (WebSocketRepositoryImpl.kt:618)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.access$handleMessage (WebSocketRepositoryImpl.kt:80)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl$onMessage$2$1.invokeSuspend (WebSocketRepositoryImpl.kt:781)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:100)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)

@dshokouhi
Copy link
Member Author

Latest beta from July 9 10470

Exception java.lang.IllegalStateException:
  at kotlinx.coroutines.CancellableContinuationImpl.alreadyResumedError (CancellableContinuationImpl.kt:559)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl (CancellableContinuationImpl.kt:524)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default (CancellableContinuationImpl.kt:497)
  at kotlinx.coroutines.CancellableContinuationImpl.resumeWith (CancellableContinuationImpl.kt:368)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.handleMessage (WebSocketRepositoryImpl.kt:685)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl.access$handleMessage (WebSocketRepositoryImpl.kt:86)
  at io.homeassistant.companion.android.common.data.websocket.impl.WebSocketRepositoryImpl$onMessage$2$1.invokeSuspend (WebSocketRepositoryImpl.kt:851)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:108)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:103)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)

jpelgrom pushed a commit that referenced this issue Sep 12, 2024
…) (#4616)

* Prevent socket response continuation being called multiple times (3338)

Coroutines continuations can only be invoke once, see CancellableContinuation. Use atomic boolean to ensure the continuation is called only once in a thread safe way.

* Update import ordering

* Add warning log message to coroutines continuation

Log a warning message so that it's more visible if a websocket response is invoked multiple times

* Set initial continuation invocation to false

The default value must be false as the continuation property is mutable. The value is always assigned after the object is created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants