Skip to content

RDKBWIFI-348: Fix Race condition between timer tasks and scheduler execution#908

Merged
gsathish86 merged 2 commits intordkcentral:developfrom
rakhilpe:timer_schedule_fix
Feb 17, 2026
Merged

RDKBWIFI-348: Fix Race condition between timer tasks and scheduler execution#908
gsathish86 merged 2 commits intordkcentral:developfrom
rakhilpe:timer_schedule_fix

Conversation

@rakhilpe
Copy link
Contributor

RDKBWIFI-348: Fix Race condition between timer tasks and scheduler execution

Reason for change: The existing timeout calculation is based on current time scheduler start. If the scheduler timeout and timer task interval is same, small micro seconds difference in scheduler start make the timer task to skip the execution and need to wait till the next iteration.
Fixed the issue -
a) by modifying the timeout calculation based on last timeout instead of current time. And
b) updated timeout while adding a new timer task with start_immediately as false.

Test Procedure: Ensure the timer task run in configured intervals and no regressions. Risks: Medium
Priority: P1

Copilot AI review requested due to automatic review settings February 16, 2026 15:01
@rakhilpe rakhilpe requested a review from a team as a code owner February 16, 2026 15:01
@github-actions github-actions bot added the community contribution Contributions from community. label Feb 16, 2026
…ecution

Reason for change: The existing timeout calculation is based on current time scheduler start.
If the scheduler timeout and timer task interval is same, small micro seconds difference in scheduler start make the timer task to skip the execution and need to wait till the next iteration.
Fixed the issue a) by modifying the timeout calculation based on last timeout instead of current time. And
                b) updated timeout while adding a new timer task with start_immediately as false.
Test Procedure: Ensure the timer task run in configured intervals and no regressions.
Risks: Medium
Priority: P1

Signed-off-by: Rakhil P E <rakhilpe001@gmail.com>
Copy link

Copilot AI left a 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 pull request fixes a race condition in the timer task scheduler where small microsecond timing differences could cause timer tasks to skip executions. The fix changes the timeout calculation logic from being based on the current time to being based on the previous timeout, which maintains fixed intervals and prevents timing drift.

Changes:

  • Modified timeout calculation in scheduler_calculate_timeout to use previous timeout instead of current time for determining next execution time
  • Added proper timeout initialization for timer tasks created with start_immediately=false to ensure they don't execute immediately
  • These changes ensure timer tasks maintain consistent execution intervals even with minor timing variations in scheduler execution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
tt->execute = timespecisset(&tt->timeout);
timespecadd(&t_now, &(tt->interval), &(tt->timeout));
timespecadd(&(tt->timeout), &(tt->interval), &(tt->timeout));
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The timeout calculation has been changed from current-time-based to previous-timeout-based to maintain fixed intervals and prevent timing drift. This ensures timer tasks execute consistently even with small microsecond variations in scheduler timing.

However, be aware that if a timer task execution is significantly delayed (e.g., system suspension, heavy load, or long-running callbacks), the task may execute multiple times in quick succession to catch up to the intended schedule. Consider whether this catch-up behavior is appropriate for all use cases, and document it if it's intentional.

The same consideration applies to the high-priority task timeout calculation on line 501.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@amarnathhullur amarnathhullur left a comment

Choose a reason for hiding this comment

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

Looks good to me

@gsathish86 gsathish86 merged commit f4c9de9 into rdkcentral:develop Feb 17, 2026
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community contribution Contributions from community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants