Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 8 Blazor - Memory Corruption #102046

Closed
1 task done
TomElcome opened this issue May 9, 2024 · 7 comments · Fixed by #102570
Closed
1 task done

.NET 8 Blazor - Memory Corruption #102046

TomElcome opened this issue May 9, 2024 · 7 comments · Fixed by #102570
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-meta-mono
Milestone

Comments

@TomElcome
Copy link

TomElcome commented May 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Ran into what looks like memory corruption in my blazor project. This only seems to happen in web assembly and in the release configuration in visual studio. It also doesn't seem to occur in .NET 7. Code used to cause this error is pictured below:

<span>Scroll down to item 1000 to view memory corruption</span>
@for (int j = 0; j < 2000; j++)
{
    <div>This works as expected: @(j < 1500 ? j.ToString() : "N/A")</div>
    <div>This becomes corrupted: @(j < 1500 ? j : "N/A")</div>
}

The top line in each iteration is showing the expected behaviour of the code. The bug occurs only when: rendering large quantities of data, using the ternary operator and when we are not explicitly converting 'j' to a string

Example of the error occuring:
image

Expected Behavior

All values would be rendered for each iteration of the for loop without showing corrupted text.

Steps To Reproduce

Create standard Blazor WebAssembly App. and change configuration to release. Next put erroneous block of code onto page.
Then build and run, scrolling down the page to encounter the memory corruption.

Exceptions (if any)

No response

.NET Version

8.0.0

Anything else?

Sample Project Repository: https://github.com/TomElcome/BlazorWasmMemoryCorruption
REPL: https://blazorrepl.telerik.com/myOTEtbf19p2whkm36

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore May 9, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 9, 2024
@mkArtakMSFT
Copy link
Member

@lewing FYI

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 9, 2024
@vcsjones vcsjones added arch-wasm WebAssembly architecture area-Codegen-meta-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 10, 2024
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @lambdageek
See info in area-owners.md if you want to be subscribed.

@steveisok
Copy link
Member

@kg can you please investigate?

@kg
Copy link
Member

kg commented May 10, 2024

Reduced repro:

<span>Scroll down to item 1000 to view memory corruption</span>
@for (int j = 0; j < 2000; j++)
{
    <div>@(j < 1500 ? "test" : "N/A")</div>
    <div>@(j < 1501 ? j : "N/A")</div>
}

Produces:

998
test
<garbage>
test
<garbage>
test
<garbage>

What appears to be happening is that the buffer blazor uses to send strings and other data to the DOM is either getting corrupted or it's being read from using the wrong type. Have to dig in deeper to figure out why.

@kg
Copy link
Member

kg commented May 10, 2024

cc @BrzVlad this appears to be related to interpreter tiering; it breaks as soon as the loop (j++) iterates ~999 times, which aligns with interp tiering threshold of 1000. i think the loop is getting tiered and then RenderTreeBuilder.AddContent is passed the wrong thing somehow.

EDIT: I should note it seems like this may be fixed in 9.

@lewing lewing added this to the 9.0.0 milestone May 10, 2024
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label May 10, 2024
@lewing
Copy link
Member

lewing commented May 10, 2024

@kg so you were able to reproduce in net8.0 but not net9.0?

@kg
Copy link
Member

kg commented May 10, 2024

@kg so you were able to reproduce in net8.0 but not net9.0?

I haven't reproduced it locally, but Mackinnon tested it on both and couldn't repro in 9.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Codegen-meta-mono
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants