Type loading deep type hierarchy with an intermediate or base type missing can trigger stack overflow
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
The type loading in the runtime is a recursive algorithm that consumes quite significant amount of stack space per type hierarchy level. Moreover, the stack consumption gets amplified if an exception is thrown when attempting to load one of the intermediate or the base type due to the behavior of native EH on Windows. On each level, there is `EX_TRY` with `EX_HOOK` block that does some state maintenance and then rethrows. That again grows the stack since native EH on Windows doesn't unwind the stack until a catch block completes without exceptions.
A first party has hit a problem when a 57 level trivial type hierarchy consumed more than 1.5MB of stack space, triggering stack overflow. Just the loading of that type hierarchy without an exception consumes ~500kB of memory.
The amplification due to the native EH can be mitigated by replacing the `EX_HOOK` by `EX_CATCH` and rethrowing after the catch (for `Exception` derived exceptions).
However, it seems it would make sense to remove the recursion if possible.
Contributor guide
Research direction
No files or tests are named; begin by locating the runtime's recursive type-loading path and the EX_HOOK and EX_CATCH exception-handling macros. Reproduce the 57-level hierarchy with a missing intermediate or base type, then compare stack use and confirm that loading no longer triggers stack overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100