-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Prevent socket response continuation being called multiple times (#3338) #4616
Prevent socket response continuation being called multiple times (#3338) #4616
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Isn't that the stack trace we already have as a crash? |
Yes, with these changes, it won't be logged out any more so it will be less obvious when the problem occurs. A better idea would probably be to log a warning when the second invocation is attempted. |
...n/src/main/java/io/homeassistant/companion/android/common/data/websocket/WebSocketRequest.kt
Outdated
Show resolved
Hide resolved
5727eda
to
24378db
Compare
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.
Log a warning message so that it's more visible if a websocket response is invoked multiple times
The default value must be false as the continuation property is mutable. The value is always assigned after the object is created.
24378db
to
7500421
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the workaround!
Summary
Prevent the crash outlined in #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. While this does not fix the underlying cause it will prevent any more crashes.
Any other notes
We could log the stack trace whenever the continuation is invoked a second time in order to help identify where the second call comes from.