Commit 63e28ea
[NativeAOT] Print OOM message before Abort() on Linux (#125311)
On Linux, NativeAOT processes terminating due to `OutOfMemoryException` (e.g. with `DOTNET_GCHeapHardLimit` set) printed only `Aborted` with no diagnostic context.
## Root cause
`RuntimeExceptionHelpers.FailFast` detects the preallocated OOM
exception via `minimalFailFast = (exception ==
PreallocatedOutOfMemoryException.Instance)` and skips **all** stderr
output to avoid heap allocations — leaving the user with no indication
of why the process died.
## Fix
In the `minimalFailFast` path, print a hardcoded OOM message to stderr
before calling `Abort()`. The write is wrapped in `try/catch {}` so a
secondary allocation failure silently falls through to the existing
abort path.
**Before:** `Aborted`
**After:** `Out of memory.`
## Test
Added a new `OomHandling` smoke test in
`src/tests/baseservices/exceptions/OutOfMemoryException/`. The test
spawns itself as a subprocess with `DOTNET_GCHeapHardLimit=20000000` (32
MB) set, waits for the subprocess to run out of memory, and verifies
that some OOM message appears in stderr. This covers both the
preallocated OOM path (the fix) and the existing unhandled-exception
path. The test is skipped on mobile and browser platforms that do not
support process spawning.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>[NativeAOT] Out of memory reporting on
Linux</issue_title>
> <issue_description>### Repro
> ```csharp
> var l = new List<object>();
> for (; ; ) l.Add(new object());
> ```
>
> Run the native aot compiled binary with with `export
DOTNET_GCHeapHardLimit=2000000` set
>
> ### Actual result
>
> `Aborted`
>
> ### Expected result
>
> `Out of memory.`
>
> (Reported by partner team.)</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@</author><body>
> Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
> See info in
[area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md)
if you want to be subscribed.
> <details>
> <summary>Issue Details</summary>
> <hr />
>
> ### Repro
> ```csharp
> var l = new List<object>();
> for (; ; ) l.Add(new object());
> ```
>
> Run the native aot compiled binary with with `export
DOTNET_GCHeapHardLimit=2000000` set
>
> ### Actual result
>
> `Aborted`
>
> ### Expected result
>
> `Process is terminating due to OutOfMemoryException`
>
> (Reported by partner team.)
>
> <table>
> <tr>
> <th align="left">Author:</th>
> <td>jkotas</td>
> </tr>
> <tr>
> <th align="left">Assignees:</th>
> <td>-</td>
> </tr>
> <tr>
> <th align="left">Labels:</th>
> <td>
>
> `area-NativeAOT-coreclr`
>
> </td>
> </tr>
> <tr>
> <th align="left">Milestone:</th>
> <td>8.0.0</td>
> </tr>
> </table>
> </details></body></comment_new>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #82337
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Co-authored-by: Eduardo Velarde <32459232+eduardo-vp@users.noreply.github.com>
Co-authored-by: Eduardo Velarde <evelardepola@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent 1b366f4 commit 63e28ea
4 files changed
Lines changed: 195 additions & 23 deletions
File tree
- src
- coreclr/nativeaot/System.Private.CoreLib/src/System
- libraries/System.Private.CoreLib/src/Internal
- tests/baseservices/exceptions/OutOfMemoryException
Lines changed: 43 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
205 | 207 | | |
206 | | - | |
207 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
208 | 218 | | |
209 | | - | |
| 219 | + | |
210 | 220 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | 221 | | |
215 | 222 | | |
216 | 223 | | |
| |||
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
238 | | - | |
239 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
240 | 259 | | |
241 | 260 | | |
242 | 261 | | |
| |||
266 | 285 | | |
267 | 286 | | |
268 | 287 | | |
269 | | - | |
270 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
271 | 303 | | |
272 | 304 | | |
273 | 305 | | |
| |||
Lines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 15 | + | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
25 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
Lines changed: 115 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments