Skip to content

Scheduled tasks stop working after 2023.04.14 1:41:36 UTC #85473

Closed

Description

@ugurdal

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've blazor wasm app that i need to run scheduled task periodically in the background. I'm triggering new Task after first render of MainLayout's OnAfterRender method. Lets say this task will print out current date every 1 second to browser console. Exactly at 2023.04.14 1:41.36 PM UTC task stops without any exception. I am able to reproduce the same error by changing the Date and time settings on my Windows 11 device. So far i've tried while loop, periodic timer, System.Threading.Timer, System.Timers.Timer or another approach that i found at stack overflow, but all of them stops working at exactly same time.

We have customers who use this app and are in different time zones. This task stopped working on all of them at the same time.

By the way this approach is working almost three years without any issues. We couldn't find any solution to this problem and we don't know when or will its going to happen in the future.

sample repo: https://github.com/ugurdal/BlazorWasmBackgroundTaskDemo

Expected Behavior

Loops will work without any issue

Steps To Reproduce

  1. create new blazor wasm project via dotnet new blazorwasm -n MyBlazorApp
  2. add following lines to MainLayout.Razor ( you can try while loop or periodic timer. they will both behave the same )
protected override void OnAfterRender(bool firstRender)
{
    if (firstRender)
    {
        _ = Task.Run(async () =>
        {
            while (true)    
            {
                await Task.Delay(1 * 1000);
                Console.WriteLine("ping-timer utc {0}", DateTime.UtcNow.ToUniversalTime());
            }

            // var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
            // while (await timer.WaitForNextTickAsync())
            // {
            //     Console.WriteLine("ping-timer utc {0}", DateTime.UtcNow.ToUniversalTime());
            // }
        });
    }

    base.OnAfterRender(firstRender);
}
  1. set the date time to 2023.04.14 and a few seconds before 1:41:36 PM UTC ( give app a couple second to start, e.g 1:41.20 )
  2. start application via dotnet watch run, and new browser tab will open
  3. app will print out current date to browser console
  4. exactly at 1:41:36 UTC you'll see that nothing prints out to console

this screenshot was taken from the Microsoft Edge console
console

Exceptions (if any)

No response

.NET Version

7.0.203

Anything else?

No response

Activity

  1. ghost added
    needs-area-label
    on Apr 27, 2023
  2. ghost added
    untriaged
    on Apr 27, 2023
  3. added
    arch-wasm
    and removed
    untriaged
    needs-area-label
    on Apr 27, 2023
  4. added this to the 8.0.0 milestone on Apr 28, 2023
  5. kg commented on Apr 28, 2023

    @kg
    Contributor

    This is likely because new Date().valueOf() | 0 wrapped around from positive to negative near this point in time:

    > Date.parse("4/14/2023 1:40:00 PM UTC").valueOf() | 0
    2147387264
    > Date.parse("4/15/2023 1:40:00 PM UTC").valueOf() | 0
    -2061180032 
  6. ugurdal commented on Apr 28, 2023

    @ugurdal
    Author

    To be more precise, at exactly 1:41:36:384 PM UTC, the time is wrapped from positive to negative.

    Date.parse("4/14/2023 1:41:36:383 PM UTC").valueOf() | 0
    2147483647
    Date.parse("4/14/2023 1:41:36:384 PM UTC").valueOf() | 0
    -2147483648

    I guess this issue will happen again on 6/03/2023 6:44:23 AM UTC. He is my new test; I've updated the Windows time and started the application again.

    Console output stopped at 6:44:23 AM UTC

    Screenshot_2

  7. kg commented on May 2, 2023

    @kg
    Contributor

    Now that I'm attempting to reproduce this in my Linux environment, I can't reproduce it. What is your system time zone?

  8. ghost added
    in-pr
    on May 2, 2023
  9. ugurdal commented on May 2, 2023

    @ugurdal
    Author

    Currently we've clients that they reported this problem was experienced in UTC +03:00 Istanbul and UTC +04:00 Baku on Windows environments.

  10. ghost removed
    in-pr
    on May 3, 2023
  11. reopened this on May 3, 2023
  12. kg commented on May 3, 2023

    @kg
    Contributor

    I believe the combo of #85677 and #85660 should resolve this, but I'm not totally certain because I couldn't reproduce the failure. Will leave open until we're sure it's fixed.

  13. ghost added
    in-pr
    on May 4, 2023
  14. ghost removed
    in-pr
    on May 4, 2023
  15. ghost added
    in-pr
    on May 4, 2023
  16. ghost removed
    in-pr
    on May 12, 2023
  17. modified the milestones: 8.0.0, 7.0.x on May 15, 2023
  18. pavelsavara commented on May 29, 2023

    @pavelsavara
    Member

    Validated on 7.0.7

  19. ghost locked as resolved and limited conversation to collaborators on Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-VM-meta-mono

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions