-
Notifications
You must be signed in to change notification settings - Fork 5
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 multi-threading crash to desktop when publishing ATIS to hub #80
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in the Changes
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
vATIS.Desktop/Ui/ViewModels/AtisStationViewModel.cs (1)
1149-1170
: Consider enhancing the timer implementation.While the current implementation is functional, consider these improvements:
- Extract the hardcoded 3-minute interval to a configuration value
- Add cancellation token support for graceful shutdown
- Consider using a different async pattern instead of async void
Here's a suggested implementation:
private async Task PublishAtisToHub() { // Publish ATIS immediately await PublishAtis(); // Dispose of the existing timer to start a new one. _publishAtisTimer?.Dispose(); _publishAtisTimer = null; + // Get interval from configuration + var interval = TimeSpan.FromMinutes(_appConfig.AtisPublishInterval ?? 3); + // Set up a new timer to re-publish ATIS - _publishAtisTimer = new Timer(PublishAtisTimerCallback, null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3)); + _publishAtisTimer = new Timer(async _ => await PublishAtisWithErrorHandling(), null, interval, interval); } -private async void PublishAtisTimerCallback(object? state) +private async Task PublishAtisWithErrorHandling() { try { await PublishAtis(); } catch (Exception ex) { Log.Error(ex, "Failed to publish ATIS to hub"); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
vATIS.Desktop/Ui/ViewModels/AtisStationViewModel.cs
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: build (macos-latest)
- GitHub Check: build (windows-latest)
- GitHub Check: Analyze (cpp)
- GitHub Check: build (ubuntu-latest)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (3)
vATIS.Desktop/Ui/ViewModels/AtisStationViewModel.cs (3)
66-66
: LGTM! Good type refinement.Using the concrete
Timer
type instead ofIDisposable
interface improves code clarity and provides better access to timer-specific functionality.
579-581
: LGTM! Proper resource cleanup.The timer disposal is implemented correctly, following the proper IDisposable pattern by disposing of the timer and nullifying the reference.
1137-1147
: LGTM! Well-structured timer management.The implementation properly manages the timer lifecycle by:
- Publishing immediately before timer setup
- Cleaning up existing timer to prevent resource leaks
- Setting up a new timer with appropriate interval
This should fix the multi-threading crash by ensuring only one timer is active at a time.
Summary by CodeRabbit
Bug Fixes
Refactor