Skip to content

fix: resolve exponential timer drain in wake-up challenges by adding …#902

Open
vibhutomer wants to merge 1 commit intoCCExtractor:mainfrom
vibhutomer:fix-exponential-timer-drain
Open

fix: resolve exponential timer drain in wake-up challenges by adding …#902
vibhutomer wants to merge 1 commit intoCCExtractor:mainfrom
vibhutomer:fix-exponential-timer-drain

Conversation

@vibhutomer
Copy link

Description

This PR addresses a critical concurrency bug in alarm_challenge_controller.dart where multiple asynchronous _startTimer() loops could run simultaneously. Previously, calling restartTimer() spawned a new for loop without terminating the old one, leading to an exponential drain on the progress bar and causing users to unfairly fail wake-up challenges.

Proposed Changes

  • Introduced a _timerSessionId state variable to track the active timer lifecycle.
  • Updated restartTimer() to increment the session ID upon invocation.
  • Added a cancellation check (if (currentSessionId != _timerSessionId) break;) inside the _startTimer() async loop. This acts as a cancellation token, instantly killing orphaned loops and ensuring only a single asynchronous loop modifies progress.value at any given time.

Fixes #901

Screenshots

(Not applicable - backend logic and concurrency fix)

Checklist

  • Tests have been added or updated to cover the changes
  • Documentation has been updated to reflect the changes
  • Code follows the established coding style guidelines
  • All tests are passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Exponential timer drain in AlarmChallengeController due to orphaned async loops

1 participant