Skip to content

Throw exception if an infinite component tree is detected #16881

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

Closed
guidevnet opened this issue Nov 7, 2019 · 1 comment
Closed

Throw exception if an infinite component tree is detected #16881

guidevnet opened this issue Nov 7, 2019 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@guidevnet
Copy link

Some days ago I was refactoring the code of a healthy server-side blazor app. After some adjustments here and there, I hit debug. To my surprise, this happens:

image

The process continued to grow until it froze my operating system and crashed with 31 of my 32GB of RAM consumed.

After two days of digging, I finally found out what was causing the issue: a simple @layout MainLayout inside the global _imports.razor file. This caused a recursive and endless component tree.

Of course, it is my fault: I copied some repeated @using and @inject and put together in one _imports file, and this @layout come along. However, this was extremely hard to debug. No breakpoints getting hit; except if I put on the Html.RenderComponentAsync<App> in the _Host file. After hitting F11, the next thing that happens is an OutOfMemoryException. The stack trace showed just the same line of code, and a bunch of framework calls. After two days of frustration, I was starting to think that I was facing this issue.

Describe the solution you'd like

Would be nice if the runtime is somewhat capable of throwing an exception (with a friendly and helpful message) if it detects a overly-deep and recursive tree of components (before the OutOfMemoryException). I can see this problem occurring with more people, in several ways.

@javiercn javiercn added the area-blazor Includes: Blazor, Razor Components label Nov 7, 2019
@javiercn
Copy link
Member

javiercn commented Nov 7, 2019

@guidevnet Thanks for contacting us.

We don't plan to do this as Blazor doesn't check for circular dependencies the same way the C# compiler doesn't check that recursive methods converge, it is in general too expensive or directly intractable.

@javiercn javiercn closed this as completed Nov 7, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants