Repository navigation
Description
Description
I'm experiencing a deadlock with .NET 6.x on Mac OS under Rosetta. It's a really weird one:
- It doesn't always happen.
- It usually only happens within the first few minutes of application start.
You can find a full sample here: https://gist.github.com/CharlieEriksen/2f04ec835a72adfe2643a2a0ffdf7679
Here's what seems to be the most relevant part of a sample. It's the same pattern always:
Thread 0xdf373 1001 samples (1-1001) priority 31 (base 31)
1001 thread_start + 15 (libsystem_pthread.dylib + 7123) [0x7ff801266bd3]
1001 _pthread_start + 125 (libsystem_pthread.dylib + 25043) [0x7ff80126b1d3]
1001 CorUnix::CPalThread::ThreadEntry(void*) + 407 (jswzl.Server + 7158375) [0x1013dda67]
1001 (anonymous namespace)::CreateSuspendableThread(void (*)(void*), void*, char16_t const*)::$_0::__invoke(void*) + 116 (jswzl.Server + 1892484) [0x100ed8084]
1001 WKS::gc_heap::bgc_thread_function() + 257 (jswzl.Server + 3310881) [0x101032521]
1001 WKS::gc_heap::gc1() + 836 (jswzl.Server + 3201796) [0x101017b04]
1001 WKS::gc_heap::background_mark_phase() + 858 (jswzl.Server + 3205786) [0x101018a9a]
1001 WKS::gc_heap::revisit_written_pages(int, int) + 1011 (jswzl.Server + 3315155) [0x1010335d3]
1001 SoftwareWriteWatch::GetDirty(void*, unsigned long, void**, unsigned long*, bool, bool) + 65 (jswzl.Server + 3378033) [0x101042b71]
1001 FlushProcessWriteBuffers + 147 (jswzl.Server + 7152259) [0x1013dc283]
1001 thread_get_register_pointer_values + 144 (libsystem_kernel.dylib + 72297) [0x7ff80123ca69]
1001 thread_get_state + 140 (libsystem_kernel.dylib + 35498) [0x7ff801233aaa]
1001 mach_msg2_trap + 10 (libsystem_kernel.dylib + 5554) [0x7ff80122c5b2]
*1001 ??? (kernel.release.t8112 + 5328152) [0xfffffe0008900d18] (blocked by turnstile waiting for jswzl.Server [45872] thread 0xdf374)
Thread 0xdf374 1001 samples (1-1001) priority 31 (base 31)
1001 thread_start + 15 (libsystem_pthread.dylib + 7123) [0x7ff801266bd3]
1001 _pthread_start + 125 (libsystem_pthread.dylib + 25043) [0x7ff80126b1d3]
1001 CorUnix::CPalThread::ThreadEntry(void*) + 407 (jswzl.Server + 7158375) [0x1013dda67]
1001 ThreadNative::KickOffThread(void*) + 170 (jswzl.Server + 1690938) [0x100ea6d3a]
1001 ManagedThreadBase::KickOff(void (*)(void*), void*) + 32 (jswzl.Server + 1369424) [0x100e58550]
1001 ManagedThreadBase_DispatchOuter(ManagedThreadCallState*) + 296 (jswzl.Server + 1368040) [0x100e57fe8]
1001 ThreadNative::KickOffThread_Worker(void*) + 136 (jswzl.Server + 1690728) [0x100ea6c68]
1001 DispatchCallSimple(unsigned long*, unsigned int, unsigned long, unsigned int) + 223 (jswzl.Server + 1596143) [0x100e8faef]
1001 CallDescrWorkerInternal + 124 (jswzl.Server + 3382761) [0x101043de9]
1001 ??? [0x1273f7ff1]
1001 ??? [0x1274034eb]
1001 ??? [0x1273f92a8]
1001 ??? [0x12d962257]
1001 ??? [0x12d962946]
1001 ??? [0x12d9631c8]
1001 ??? [0x127e7ba36]
1001 ??? [0x127e7d5c3]
1001 ??? [0x127e7d8ba]
1001 ??? [0x127e76c1e]
1001 ??? [0x1282af899]
1001 SystemNative_ForkAndExecProcess + 848 (jswzl.Server + 6841936) [0x101390650]
1001 __fork + 11 (libsystem_kernel.dylib + 30175) [0x7ff8012325df]
*1001 ??? (kernel.release.t8112 + 5328152) [0xfffffe0008900d18] (blocked by turnstile waiting for jswzl.Server [45872] thread 0xdf373)
If I understand this correctly, the GC is getting deadlocked by the fork call to spawn a new process. Based on this theory, I've tried not to spawn a process when a full GC pass is approaching. But that doesn't seem to prevent this.
Reproduction Steps
- Try spawning a lot of processes at a rapid pace
- Trigger a GC pass
- Once in a while, you will get a deadlock
- If it doesn't happen relatively quickly, restart the process and try again
Expected behavior
The process does not deadlock
Actual behavior
The process deadlocks
Regression?
No response
Known Workarounds
No response
Configuration
- .NET 6.0.13
- Ventura 13.4.1 (c)
- M1/M2
- More prone to happen on lower-memory configs
- Running x64 under Rosetta
Other information
No response
Known Issue Error Message
DO NOT USE JSON BELOW IF THIS IS A BUILD BREAK otherwise build analysis will allow pull requests to merge that break the build worse. For a build break, do not use this issue form. Make a regular new issue.
Fill the error message using step by step known issues guidance.
{
"ErrorMessage": "",
"ErrorPattern": "",
"BuildRetry": false,
"ExcludeConsoleLog": false
}Report
Summary
| 24-Hour Hit Count | 7-Day Hit Count | 1-Month Count |
|---|---|---|
| 0 | 0 | 0 |
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
CharlieEriksen commentedon Jul 20, 2023
@tmds you may find this interesting, as I'm seeing this while using Tmds.ExecFunction.
CharlieEriksen commentedon Jul 21, 2023
I've noticed another clue. The subprocess being spawned often crashes with information this like this:
So if the process start call does not get a process due to it instantly crashing due to being unable to get memory, then it never returns.
mangod9 commentedon Jul 24, 2023
@janvorli @kouvel. This isnt a GC issue but a thread suspension issue. @CharlieEriksen, just confirming that you only notice this under emulation. Does it also occur with .NET 7?
CharlieEriksen commentedon Jul 25, 2023
@mangod9 The software I'm experiencing this with hasn't been able to migrate to 7.0 yet, nor publish an arm64 build. So I'm not 100% sure. But I can play around with it and see if I can get something together to test with.
So if it's not a GC issue, I've been barking up the wrong tree. Are there any potential workarounds that could be implemented to prevent this occurrence?
[-]GC deadlock on spawning new process on OSX [/-][+]GC deadlock on spawning new process on OSX under Rosetta[/+]rolfbjarne commentedon Oct 9, 2024
I think I'm running into the same thing, process is stuck here:
Sample of dotnet.txt
This is with .NET 9.0.100-rc.2.24475.4
wtgodbe commentedon Jun 27, 2026
Still reproduces on .NET 11 (
11.0.0-preview.6.26318.108), osx-x64 under Rosetta on Apple Silicon CI agents. A hang-dump from a timed-out dotnet/aspnetcore CI leg shows the identical cycle: one thread stuck inSystemNative_ForkAndExecProcess → __fork(an MSBuildToolTasklaunching a child process), deadlocked against the background-GC thread inrevisit_written_pages → SoftwareWriteWatch::GetDirty → FlushProcessWriteBuffers → thread_get_state. Default workstation concurrent GC; settingDOTNET_gcConcurrent=0avoids it. Running the arm64-native runtime (no Rosetta) also avoids it.Failing build: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1483935&view=results
Run macOS quarantine test leg natively on arm64 (avoid Rosetta deadlock)
Run macOS quarantine leg arm64-native only on Apple Silicon agents
Use DOTNET_gcConcurrent=0 on macOS quarantine leg to avoid fork/GC de…
janvorli commentedon Jul 21, 2026
@wtgotbe do you happen to still have a dump with this issue?
wtgodbe commentedon Jul 21, 2026
@janvorli there are dumps available in the logs of the build I linked in my comment above - here's a direct link to the .zip
janvorli commentedon Jul 21, 2026
Thank you!
janvorli commentedon Aug 4, 2026
@wtgodbe I've looked at your dumps and they don't seem to show the symptoms of the deadlock described by this issue. While two of them were in the middle of spawning a process, there isn't another thread trying to suspend the runtime for GC. I've also ran my targeted test that reliably reproduced the issue in the past and I couldn't repro it anymore.
wtgodbe commentedon Aug 4, 2026
It's likely a separate issue then - I believed it was this one based on investigation from copilot, but I'm not an expert in the area. Did the dumps show a separate deadlock?
janvorli commentedon Aug 4, 2026
The dumps only show that one thread is sitting in the posix_spawn syscall attempting to start crossgen2. Other threads are not doing anything insteresting - mostly idle a waiting.
Was there anything unusual in the console output for those runs? And is there an easy way for me to try to repro it locally?
wtgodbe commentedon Aug 4, 2026
Not that I can see - here's the most recent example: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1537189&view=logs&j=48c285a2-daf4-5ecb-cb99-42232769ca29&t=73646f8d-7520-5361-e1ad-d9d207b2cd21
This might do it (on a mac):