Skip to content

Blazor WebAssembly crashes on mobile devices with low RAM #61925

Closed

Description

@martinmogusu

Describe the bug

Blazor WebAssembly apps crash on devices with low RAM

To Reproduce

I have created a minimal example at https://github.com/martinmogusu/CrashTest
The code is from the default WebAssembly template dotnet new blazorwasm

I have also hosted the site on Azure Static Web Apps here: https://icy-sky-0892af903.azurestaticapps.net/

If you load the site on a device with 1GB RAM, the app crashes. On the UI you see "An unhandled error has occurred"
On the browser console logs you find this error:

Uncaught (in promise) TypeError: Failed to execute 'arrayBuffer' on 'Response': body stream already read

TypeError: Failed to execute 'arrayBuffer' on 'Response': body stream already read
window.Module.s.printErr @ blazor.webassembly.js:1

I was able to view the console logs by using Kiwi Browser for android, which has devtools.
The same site works okay on devices with higher RAM.

Further technical details

  • ASP.NET Core version: 6.0
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: Visual studio 2022
  • Include the output of dotnet --info:
dotnet --info Output
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  3.1.301 [C:\Program Files\dotnet\sdk]
  3.1.415 [C:\Program Files\dotnet\sdk]
  5.0.403 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]
  6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Activity

  1. TanayParikh commented on Nov 16, 2021

    @TanayParikh
    Contributor

    Were you seeing a crash in Chrome as well? Supported browsers are listed here: https://docs.microsoft.com/en-us/aspnet/core/blazor/supported-platforms?view=aspnetcore-6.0. Note, Kiwi isn't on the list of supported browsers.

  2. martinmogusu commented on Nov 16, 2021

    @martinmogusu
    Author

    Yes, I'm seeing the crash on Chrome on Android as well. I'm using the latest version of chrome (95.0.4638.74)

  3. frieddumplings commented on Nov 20, 2021

    @frieddumplings

    Also seeing it in chrome beta/android 97.0.4692.20.

    The website just gives the "An unhandled error has occured. Reload" message - (clicking on reload for me dosen't actually do anything).

    .Net Core 6.0 empty/default client/server project (nothing changed).

    Using a VPS that has 2GB of ram to host my page (Just the default client/server template) . It seems to be okay when navigating normally using buttons/clicking on links, but if I modify the url through the search bar (by typing) I get this error quite frequently. Phone is a Galaxy S9 SM-G960F running android 10.

    I've tested on an older version of chrome as well (80.0.3987.99) and its harder(?) or almost impossible to reproduce the error.

    edit (this older version was chrome stable)
    (Also forgot to mention, blazor project. If that makes any difference).

    Screenshot_8

    (Edit again: Added a list of server processes) CPU** and ram usage hovers around 30~50%. Haven't really monitored when changing pages but shouldnt(?) be an issue, nothing fancy installed. Just SQLServer and a bunch of default stuff)

    Screenshot_2
    Screenshot_3

  4. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 22, 2021
  5. mkArtakMSFT commented on Nov 22, 2021

    @mkArtakMSFT
  6. frieddumplings commented on Nov 23, 2021

    @frieddumplings
  7. added this to the milestone on Nov 29, 2021
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 29, 2021
  9. removed this from the milestone on Nov 30, 2021
  10. 10 remaining items

  11. pavelsavara commented on Dec 22, 2022

    @pavelsavara
    Member

    I will spend some time next year on looking on this, but for now some hints:

    1. Browsers can't do streaming wasm instantiation when content type HTTP header is wrong. That consumes more memory. See also WebAssembly compilation fallback logic is wrong. May need some further docs about configuring memory limits. aspnetcore#42055
    2. you could use <EmccTotalMemory>xxx</EmccTotalMemory> in your .csproj file together with <WasmBuildNative>true</WasmBuildNative> or with AOT. Where xxx is memory size which still works for your app.

    Remember that memory requirements of your app is not all we need here. We also expand IL->IR for interpreted methods. And the browser JIT will have to compile all the code too, consuming CPU and memory.

    Perhaps for low powered mobile devices, consider server side rendering, where possible.
    Maybe we should define some minimal spec on which WASM is supported.

  12. Pethical commented on Dec 22, 2022

    @Pethical

    The headers are ok in my application. I have a Samsung Galaxy Note 10+ phone and the application can't load because this problem. If this is a low powered phone, then please tell me what is a high end device. And what can I define as minimum spec? A phone with 64Gb ram and 32 arm cores? 😅
    Basically, net 5 is working like a charm, so I downgraded my apps. This is a security flaw and can cause problems, but no other way exists. The net 5 is the Windows XP today. We can't upgrade. 😂

  13. pavelsavara commented on Dec 22, 2022

    @pavelsavara
    Member

    Did EmccTotalMemory help?

  14. boukenka commented on Dec 26, 2022

    @boukenka

    @simpsoc Which value did you define for xxx?

    <EmccTotalMemory>xxx</EmccTotalMemory>
  15. pavelsavara commented on Jan 5, 2023

    @pavelsavara
    Member

    Searching for Module["INITIAL_MEMORY"] in the final dotnet.js gives me following answers for vanilla Blazor template

    • net6, release, no AOT, no relink: 16777216
    • net7, release, no AOT, no relink: 16777216
    • net8, release, no AOT, no relink: 536870912
    • net6, release, relink: 536870912
    • net7, release, relink: 536870912
    • net8, release, relink: 536870912

    It is set here

    <EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">$(EmccTotalMemory)</EmccInitialHeapSize>
    <EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">536870912</EmccInitialHeapSize>

    and applies for customers anytime they do relink (even without AOT) for example via <WasmBuildNative>true</WasmBuildNative>
    or by just having wasm-tools workload installed!

    workload will pass --initial-memory=536870912 to emcc

    this is probably the PR which introduced it #52941 which is Net6 timeframe

    I was not able to replicate the issue with the repro repo without relink.

  16. pavelsavara commented on Jan 5, 2023

    @pavelsavara
    Member

    questions: @radical @lewing @maraf @kg

    • what should be the default value for no-relink (no workload)
    • what should be the default value for relink
    • what should be the default value for AOT
      • I suspect we increased it for some reasons with AOT builds and re-link is just side effect ?
      • why did we go for such large value ?
    • Should we create patch for net7 ?
    • Should we create patch for net6 ?

    Same questions as in #66313

  17. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 19, 2023
  18. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Feb 8, 2023
  19. pavelsavara commented on Feb 24, 2023

    @pavelsavara
    Member

    Fixed by #80849

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions