runtime: Blazor WebAssembly crashes on mobile devices with low RAM

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 25 (9 by maintainers)

Most upvoted comments

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 https://github.com/dotnet/runtime/blob/70aadafa7e103821563c5247e90cafb6a138ad32/src/mono/wasm/build/WasmApp.Native.targets#L190-L191 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 https://github.com/dotnet/runtime/pull/52941 which is Net6 timeframe

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

@simpsoc Which value did you define for xxx?

<EmccTotalMemory>xxx</EmccTotalMemory>

@boukenka

I set it to 16777216(1024(bytes) x 1024(kilobytes) x 16 = 16MB).

I had seen another post that was mostly msft engineers discussing the issue earlier in the year. I think I initially found it by searching my specific error message. This was a value that someone mentioned fixing the issue in their testing. The discussion seemed to mostly focus around implementing the ability to make the change vs the change already being something that could be made. I did some googling around EmccTotalMemory and webassembly, blazor, wasm keywords but the only results I found were for emscripten, which is a 3rd party webassembly compiler that is used for building the webassembly. Without any results or documentation focusing around blazor i didn’t realize it was a configurable parameter. @pavelsavara suggesting changing that value in csproj and adding the native build flag is as close to any instructions or documentation as I’ve seen for this. His suggestion triggered my memory to go back and look at that thread for the value they’d used.

@pavelsavara

  1. 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.

This helped in my case. I’ve gone from seeing 3.5-4gb of memory consumed within a few actions to under 1gb.

Thank you

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