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

Prevent socket response continuation being called multiple times (#3338) #4616

Conversation

ShaunPlummer
Copy link
Contributor

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.

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ShaunPlummer

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!

@home-assistant home-assistant bot marked this pull request as draft September 8, 2024 18:00
@home-assistant
Copy link

home-assistant bot commented Sep 8, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@ShaunPlummer ShaunPlummer changed the title Prevent socket response continuation being called multiple times (3338) Prevent socket response continuation being called multiple times (#3338) Sep 8, 2024
@ShaunPlummer ShaunPlummer marked this pull request as ready for review September 8, 2024 19:13
@jpelgrom
Copy link
Member

jpelgrom commented Sep 9, 2024

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

Isn't that the stack trace we already have as a crash?

@ShaunPlummer
Copy link
Contributor Author

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.

@home-assistant home-assistant bot marked this pull request as draft September 10, 2024 16:27
@ShaunPlummer ShaunPlummer force-pushed the 3338-prevent-multiple-continuation-execution branch from 5727eda to 24378db Compare September 10, 2024 21:41
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.
@ShaunPlummer ShaunPlummer force-pushed the 3338-prevent-multiple-continuation-execution branch from 24378db to 7500421 Compare September 11, 2024 19:18
@ShaunPlummer ShaunPlummer marked this pull request as ready for review September 11, 2024 19:29
@home-assistant home-assistant bot requested a review from jpelgrom September 11, 2024 19:29
Copy link
Member

@jpelgrom jpelgrom left a 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!

@jpelgrom jpelgrom merged commit 4838dc7 into home-assistant:master Sep 12, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants