Skip to content

[WASM] Chrome timer throttling affects runtime #51041

Closed

Description

@BrennanConroy

Chrome recently turned on intensive timer throttling. The side-effect of this is that code that relied on timers firing at certain intervals may not work as expected. We first got reports of this issue with the SignalR Javascript library (dotnet/aspnetcore#31079), as it relies on client and server pings to detect connection closures. In addition, the SignalR .NET Client library has the same issue as it uses a timer to send the same pings.

The Javascript library was fixed by relying on

Intensive throttling is not applied to timers that are scheduled from a network response handler

-https://bugs.chromium.org/p/chromium/issues/detail?id=1186569#c3

The Javascript fix is at dotnet/aspnetcore#31300 for reference.

Unfortunately, the .NET client can not do the same thing because it uses .NET patterns (async await) which go through the wasm runtime. The wasm runtime very likely uses timers for scheduling work which will be chained and have throttling applied to them.

Specifically, I was noticing that when using a System.IO.Pipeline, calling FlushAsync on a Pipe and ReadAsync from another thread was taking more than 30 seconds for the ReadAsync to return after FlushAsync finished.

TLDR:
Wasm Runtime uses timers which will be throttled on Chrome, this can result in poor behavior for apps.

A potential change that could be made is to restart timers on network handlers so they aren't throttled.

cc @lewing @davidfowl @halter73

Activity

  1. ghost added
    untriaged
    on Apr 10, 2021
  2. added
    arch-wasm
    on Apr 10, 2021
  3. removed
    untriaged
    on Apr 10, 2021
  4. added this to the 6.0.0 milestone on Apr 10, 2021
  5. lewing commented on Apr 10, 2021

    @lewing
    Member

    Thank you for the report, I'd seen some of discussion but hadn't connected all the pieces. Yes, we certainly use timers to yield to the browser while scheduling. We have a couple of options here that might help mitigate. Setting the milestone to 6 for the moment but it might be worth servicing.

    cc @kg @pavelsavara

  6. WayneHiller commented on Apr 13, 2021

    @WayneHiller

    I hope we can fix this before the 6.0 release. Anyone using Blazor Wasm with SignalR will be affected. I am ready to test a fix anytime :) Edge is affected too but it seems it has a 2 hour page idle time before the throttling kicks in.

  7. andrew-tevent commented on Apr 13, 2021

    @andrew-tevent

    These stability issues are causing us issues, so a .net 5 backport would be gratefully received.

  8. tofron commented on Apr 21, 2021

    @tofron

    I have the same issue. i'm using 3.1.14 version

  9. kg commented on Apr 21, 2021

    @kg
    Contributor

    We are currently investigating solutions for this issue. If you have specific problem scenarios (other than the already-known SignalR issue) or reliable reproduction steps it'd be good to know about them so we can make sure whatever solution we arrive at will address the problem for you.

  10. andrew-tevent commented on Apr 29, 2021

    @andrew-tevent

    @kg I added a Chrome WS messages screenshot here.

  11. pavelsavara commented on May 5, 2021

    @pavelsavara
    Member
  12. 25 remaining items

  13. lewing commented on Aug 24, 2021

    @lewing
    Member

    It's the opposite, browser vendors are throttling everything and having an active network connection lets you avoid the worst of it

    You misunderstood, I understand the issue, but the proposed PR is only for websocket connections. It would be better to apply the fix for any network activity.

    We don't have a simple way to do that since other types of network activity don't go through our runtime layer, only WebSocket does. We could potentially install hooks on fetch, XMLHTTPRequest, and WebRTC, but that's some new engineering with associated risk. It sounds like a good idea so it might be worth filing an issue.

    All networking goes through our code. Http goes through our fetch hooks (we don't bind xmlhttprequest intentionally).

  14. kg commented on Aug 24, 2021

    @kg
    Contributor

    It's the opposite, browser vendors are throttling everything and having an active network connection lets you avoid the worst of it

    You misunderstood, I understand the issue, but the proposed PR is only for websocket connections. It would be better to apply the fix for any network activity.

    We don't have a simple way to do that since other types of network activity don't go through our runtime layer, only WebSocket does. We could potentially install hooks on fetch, XMLHTTPRequest, and WebRTC, but that's some new engineering with associated risk. It sounds like a good idea so it might be worth filing an issue.

    All networking goes through our code. Http goes through our fetch hooks (we don't bind xmlhttprequest intentionally).

    I'm referring to things like third-party libraries that might be calling directly into JS

  15. pavelsavara commented on Aug 24, 2021

    @pavelsavara
    Member

    The heavy throttling in Firefox
    What throttling does Firefox have? I haven't seen any before.

    https://superuser.com/questions/1500289/how-to-aggressively-throttle-background-tabs-in-firefox-using-dom-min-background
    I guess that if we deplete the budget we would be throttled. But in my tests it didn't happen. Perhaps some CPU heavy workload could trigger that.

    Curious, why is the change limited to WS?

    The documentation I found so far only speaks about WebRTC as opt-out. We know from experience that WebSocket has same effect. Could you point me to something specific talking about fetch or XMLHTTPRequest in this context ?

    I will experiment with back end of the fetch promise when called by our BrowserHttpHandler and see if that works too.
    I don't think we should monkey-patch window.fetch to hook into third party JS.

  16. BrennanConroy commented on Aug 24, 2021

    @BrennanConroy
    MemberAuthor

    Timer throttling is caused by chained timers, if you kick off a new timer from any network response you will no longer have chained timers. Thus avoiding the throttling issue (at least until they add some new heuristic)

  17. pavelsavara commented on Aug 24, 2021

    @pavelsavara
    Member

    Timer throttling is caused by chained timers, if you kick off a new timer from any network response you will no longer have chained timers. Thus avoiding the throttling issue (at least until they add some new heuristic)

    Response to fetch is not event, but just promise.
    I implemented hook into that promise and test here pavelsavara@425252b
    But unfortunately, it does NOT prevent throttling.

    @BrennanConroy could you please look at my code to verify I have not made some simple mistake ? Or alternatively, could you please provide demo on which fetch prevents throttling ?

  18. BrennanConroy commented on Aug 24, 2021

    @BrennanConroy
    MemberAuthor

    Response to fetch is not event, but just promise.

    Oh I see, that is unfortunate 😞

  19. ghost removed
    in-pr
    on Aug 26, 2021
  20. pavelsavara commented on Aug 26, 2021

    @pavelsavara
    Member

    Keep open till 6.0 backport is done

  21. ghost added
    in-pr
    on Aug 26, 2021
  22. ghost removed
    in-pr
    on Aug 26, 2021
  23. karelz commented on Aug 26, 2021

    @karelz
    Member

    Fixed in 6.0 RC1 in PR #58160.
    Fixed in 7.0 in PR #57745

  24. ghost locked as resolved and limited conversation to collaborators on Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-Interop-mono

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions