-
Notifications
You must be signed in to change notification settings - Fork 389
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
Use retired 1s to prevent race condition #846
Conversation
WalkthroughThe changes introduced aim to enhance the stability of device connections in the application. By introducing a delay before reconnection attempts and removing unnecessary connection checks, we've mitigated potential race conditions and streamlined the connection process. Changes
Uplevel your code reviews with Entelligence.AI ProEntelligence.AI ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects. |
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.
Files selected (2)
- app/lib/providers/device_provider.dart (2)
- app/lib/services/devices.dart (1)
Files skipped from review due to trivial changes (1)
- app/lib/providers/device_provider.dart
Review comments generated (1)
- Review: 1
- LGTM: 0
Tips
Chat with Entelligence.AI Bot (@Entelligence.AI
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@Entelligence.AI
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@Entelligence.AI: ignore
anywhere in the PR description to pause further reviews from the bot.
debugPrint("ensureConnection ${_connection?.device.id} ${_connection?.status}"); | ||
if (_connection?.status == DeviceConnectionState.connected) { | ||
var pongAt = _connection?.pongAt; | ||
var shouldPing = (pongAt == null || pongAt.isBefore(DateTime.now().subtract(const Duration(seconds: 5)))); |
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.
The removal of the check for a different connected device could lead to unexpected behavior. If a connection attempt is made with a different device ID while another device is already connected, the new connection will be attempted without disconnecting the previous one. This could potentially lead to multiple devices being connected at the same time, which might not be the intended behavior.
To fix this, you should reintroduce the check and throw an exception if a different device is already connected. Here's how you can do it:
+ if (_connection != null && _connection?.device.id != deviceId) {
+ throw Exception("There is a connected device ${_connection?.device.id}, you have to disconnect it first.");
+ }
debugPrint("ensureConnection ${_connection?.device.id} ${_connection?.status}");
if (_connection?.status == DeviceConnectionState.connected) {
var pongAt = _connection?.pongAt;
var shouldPing = (pongAt == null || pongAt.isBefore(DateTime.now().subtract(const Duration(seconds: 5))));
This way, we ensure that only one device is connected at any given time, maintaining the integrity of the connection process.
Summary by Entelligence.AI