Skip to content

Commit

Permalink
[GC] Fix freelist crash - don't modify during check-only operation (#…
Browse files Browse the repository at this point in the history
…104992)

Backport of #104876 to release/8.0-staging

/cc @markples

## Customer Impact

- [x] Customer reported
- [ ] Found internally

GC can crash in region code if GC.RegisterForFullGCNotification is used.

## Regression

- [x] Yes
- [ ] No

Regression is part of general move to regions, but specific code was introduced in #48691

## Testing

The behavior is very difficult to repro and likely hadn't occurred before because it relies on a race condition, a region allocation failing, and GC.RegisterForFullGCNotification be used.  I built a custom GC that always triggers the region allocation failure path and was able to repro and verify the fix in GCPerfSim.

## Risk

Low: only impacts GC.RegisterForFullGCNotification path; only impacts notifications; may cause a notification for a full GC to be skipped, but only in a case where no other reasons for full gc occur -and- the code would be subject to the race condition and crash
  • Loading branch information
github-actions[bot] authored Jul 25, 2024
1 parent d220439 commit 9b70cf8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21595,10 +21595,13 @@ int gc_heap::generation_to_condemn (int n_initial,
}

#ifdef USE_REGIONS
if (!try_get_new_free_region())
if (!check_only_p)
{
dprintf (GTC_LOG, ("can't get an empty region -> full compacting"));
last_gc_before_oom = TRUE;
if (!try_get_new_free_region())
{
dprintf (GTC_LOG, ("can't get an empty region -> full compacting"));
last_gc_before_oom = TRUE;
}
}
#endif //USE_REGIONS

Expand Down

0 comments on commit 9b70cf8

Please sign in to comment.