Skip to content

NET 7: Calling GC.Collect() causes Access Violation exception (cx0000005) #79486

Closed

Description

@nilekirk

Description

Calling GC.Collect() when having sufficiently large objects in LOH and using the Server Garbage Collection causes Access Violation exception (cx0000005) being thrown from coreclr.dll

CoreCLR Version: 7.0.22.51805
.NET Version: 7.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: exception code c0000005

We have seen this on Windows 10 Enterprise and on Windows Server 2016

Reproduction Steps

Code

open System

[<Struct>]
type T = {
    A: DateTime
    B: int
    C: float
    D: byte }

let data: T array = Array.zeroCreate 2_000_000_000

GC.Collect()

printfn "All OK"

Project file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ServerGarbageCollection>true</ServerGarbageCollection>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

Run this with dotnet run -c release

Changes that leads to program running OK

  • Allocating with size 1_000_000_000
  • Changing the order of B and C in the struct

Expected behavior

The program writes All OK to the console.

Actual behavior

The program crashes and we see in the Event log that The process was terminated due to an unhandled exception with exception code c0000005

Regression?

We never saw this on NET 6, but it appeared immediately efter we upgraded to NET 7.

Known Workarounds

No response

Configuration

.NET version

CoreCLR Version: 7.0.22.51805
.NET Version: 7.0.0

OS

Edition Windows 10 Enterprise
Version 21H2
Installed on ‎03/‎10/‎2020
OS build 19044.2251
Experience Windows Feature Experience Pack 120.2212.4180.0

Architecture

x64

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Dec 10, 2022
  2. deeprobin commented on Dec 11, 2022

    @deeprobin
    Contributor

    Cannot reproduce with Workstation-GC.

  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Dec 12, 2022
  4. added this to the 8.0.0 milestone on Dec 12, 2022
  5. mrsharm commented on Dec 12, 2022

    @mrsharm
    Contributor

    Hi @nilekirk,

    I am failing to repro this issue on my machine. I am getting Out of Memory Errors vs. an Access Violation when I set the heap hard limit to control the amount of memory allowed in an effort to replicate the conditions. Could you please provide me the amount of memory the machine you are using has? Also, could you provide a memory dump for this issue, as well?

    Thanks in advance!

  6. samme78 commented on Dec 13, 2022

    @samme78

    I can reproduce this, I get the same application error.

    Faulting application name: ConsoleApp1.exe, version: 1.0.0.0, time stamp: 0x634eda42
    Faulting module name: coreclr.dll, version: 7.0.22.51805, time stamp: 0x634ed04e
    Exception code: 0xc0000005
    Fault offset: 0x000000000013b93e
    Faulting process id: 0x5698
    Faulting application start time: 0x01d90ed91f3bd398
    Faulting application path: C:\gitprojects\test\ConsoleApp1\ConsoleApp1\bin\release\net7.0\ConsoleApp1.exe
    Faulting module path: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0\coreclr.dll
    Report Id: ab6bce9e-0683-4f90-be8b-8aa580ae9dd3
    Faulting package full name: 
    Faulting package-relative application ID: 
    

    OS
    Edition Windows 10 Pro
    Version 21H2
    Installed on ‎2021-‎09-‎22
    OS build 19044.2251
    Experience Windows Feature Experience Pack 120.2212.4180.0

    Computer
    Processor 11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz 2.61 GHz
    Installed RAM 64,0 GB (63,2 GB usable)
    System type 64-bit operating system, x64-based processor

    Resolution
    If I change the size to 1_000_000_000 or change the order of B and C in the struct the program works as expected and prints the "All OK".

  7. mrsharm commented on Dec 14, 2022

    @mrsharm
    Contributor

    Thanks, @samme78! We are able to consistently repro this issue and are working on diagnosing the cause to work on a fix. We appreciate you reporting this issue!

  8. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 6, 2023
  9. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 9, 2023
  10. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 9, 2023
  11. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 11, 2023
  12. ghost locked as resolved and limited conversation to collaborators on Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions