Skip to content

Memory corruption leading to Access Violation in .NET 9 using parallel reads on a Trie object #110088

@Treit

Description

@Treit

Description

A small demonstration program using parallel reads of a Trie data structure lead to a memory corruption issue that crashed the program with an access violation. This does not reproduce on .NET 8 but reproduces on .NET 9.

I constructed a minimal repro project here: https://github.com/treit/ktrieIssue/

The Trie implementation is from this project: https://github.com/kpol/trie/tree/master

Reproduction Steps

  1. Clone this repo: https://github.com/treit/ktrieIssue/
  2. dotnet run --framework net9.0

Expected behavior

No access violation crash

Actual behavior

The program will eventually crash with an access violation. It may take a minute or two or it may happen immediately in my experience.

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at KTrie.Trie+<GetDescendantTerminalNodes>d__26.MoveNext()
   at KTrie.Trie+<GetTerminalNodes>d__20.MoveNext()
   at System.Linq.Enumerable+IEnumerableSkipTakeIterator`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Program+<>c__DisplayClass0_0.<<Main>$>b__0()
   at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef,System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Regression?

This appears to be a regression because I cannot reproduce it running on .NET 8.

Known Workarounds

No response

Configuration

Windows 11 x64 running on .NET 9.

I did not have a chance to try this on Linux.

I did notice that I could not reproduce it on my local workstation, but it reproduces on both my laptop and my cloud dev box.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions