-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix Check For Updates crash #14229
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
Fix Check For Updates crash #14229
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.
Pull Request Overview
This PR adds a thread join operation before reassigning the check_for_device_updates_thread to prevent potential resource leaks and undefined behavior.
- Adds a joinability check and join operation before thread reassignment
- Ensures proper cleanup of existing thread before creating a new one
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| std::weak_ptr< notifications_model > notification_model_protected( viewer.not_model ); | ||
| const context & ctx( viewer.ctx ); | ||
| if (check_for_device_updates_thread.joinable()) | ||
| check_for_device_updates_thread.join(); |
Copilot
AI
Aug 21, 2025
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.
Consider adding a detach() call as an alternative to join() to avoid blocking the current thread. If the existing thread is performing a long-running operation, join() will block until completion, which could cause UI freezing or performance issues.
| check_for_device_updates_thread.join(); | |
| check_for_device_updates_thread.detach(); |
| _updates_profile ); | ||
| std::weak_ptr< notifications_model > notification_model_protected( viewer.not_model ); | ||
| const context & ctx( viewer.ctx ); | ||
| if (check_for_device_updates_thread.joinable()) |
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 was a detached thread before as i see
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 was a detached thread before and that was the problem previous PR solved - a thread trying to access object that don't exist anymore (device disconnected)
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.
weak_ptr?
| const context & ctx( viewer.ctx ); | ||
| if (check_for_device_updates_thread.joinable()) | ||
| check_for_device_updates_thread.join(); | ||
| check_for_device_updates_thread = std::thread( [ctx, |
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.
If calling this while thread is joinable, that the task we want to perform (checking for updates) is already being performed. Do we need to create another thread and check again? Can't we use previous thread outcome?
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.
We also need to see how the UI is affected, it may get it to stuck, that's why it was detached.
If access is a problem we can try using weak_ptr
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.
We can do that, but it's not related to the thread being joinable - once we create a thread and not detach it, we need to join it, even if it finishes running, so being joinable doesn't indicate that it's still running
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.
We had no issue with check for updates before the last PR (this code was there for 5 years ), we did had an issue with the platform camera new thread no?
Am I missing something?
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.
Platform camera was another issue. This thread handling was changed because of a problem when a camera was connected and quickly disconnected.
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.
I believe all use cases were solved in the past when adding a weak ptr,
@AviaAv can you revert the previous PR locally and say which resource is not longer protected maybe we can handle it?
I even prefer to skip the request than to delay the UI if this is the solution we go with
Tracked on: [LRS-1331]