Skip to content

NextRun does sometimes not get updated or updated incorrectly #320

@ExtraTNT

Description

@ExtraTNT

So, it looks like that the NextRun value does sometimes not get updated or does get updated incorrectly.
Which leads to tasks being executed twice when they should instead only run once.
I wrote a small test application to show the problem:

...
private async Task<bool> Tester()
    {
        _logger.LogInformation("Thread id: " + Thread.CurrentThread.ManagedThreadId);
        _logger.LogInformation("Next Run: " + _scheduler.NextRun);
        _logger.LogInformation("Current Time " + DateTime.Now);
        // do something for 1 sec... (sleep 2x 1/2 sec -.-)
        Thread.Sleep(500);
        Thread.Sleep(500);
        _logger.LogInformation("After execution Time (+ 1s): " + DateTime.Now);
        return true;
    }

I ran this every 10 seconds and got the following output:

testScheduler.Worker: Information: Thread id: 9
testScheduler.Worker: Information: Next Run: 04.04.2022 14:43:40
testScheduler.Worker: Information: Current Time 04.04.2022 14:43:30
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:43:31
Exited Thread 302116
testScheduler.Worker: Information: Thread id: 9
testScheduler.Worker: Information: Next Run: 04.04.2022 14:43:50
testScheduler.Worker: Information: Current Time 04.04.2022 14:43:40
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:43:41
Exited Thread 302587
Started Thread 303062
testScheduler.Worker: Information: Thread id: 3
testScheduler.Worker: Information: Next Run: 04.04.2022 14:44:00
testScheduler.Worker: Information: Current Time 04.04.2022 14:43:50
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:43:51
Exited Thread 303063
testScheduler.Worker: Information: Thread id: 7
testScheduler.Worker: Information: Next Run: 04.04.2022 14:44:00
testScheduler.Worker: Information: Current Time 04.04.2022 14:44:00
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:44:01
testScheduler.Worker: Information: Thread id: 3
testScheduler.Worker: Information: Next Run: 04.04.2022 14:44:10
testScheduler.Worker: Information: Current Time 04.04.2022 14:44:01
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:44:02
Exited Thread 303539
testScheduler.Worker: Information: Thread id: 7
testScheduler.Worker: Information: Next Run: 04.04.2022 14:44:10
testScheduler.Worker: Information: Current Time 04.04.2022 14:44:10
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:44:11
testScheduler.Worker: Information: Thread id: 3
testScheduler.Worker: Information: Next Run: 04.04.2022 14:44:20
testScheduler.Worker: Information: Current Time 04.04.2022 14:44:11
testScheduler.Worker: Information: After execution Time (+ 1s): 04.04.2022 14:44:12

The bug occurs randomly, but in a test before a "buggy thread" was more likely to bug again and it got worse over time. But since this is not really testable i can not confirm, that it will always be this way.
I currently do not have a fix for this bug, but i will try to fix it and create a pull request.
The version i use is version-6 with dotnet 6.0 on debian gnu/linux 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions