Skip to content

ComWrappers crash under stress #120347

@jkotas

Description

@jkotas

Repro:

using System.Runtime.CompilerServices;
using Windows.Data.Json;

for (int i = 0; i < 10; i++) new Thread(Work).Start();

for (int c = 0; ; c++) { Console.WriteLine($"{c} {GC.GetTotalMemory(false)}"); GC.Collect(); GC.WaitForPendingFinalizers(); Thread.Sleep(1); }

static void Work()
{
    for (;;) JsonObject.Parse("{}");
}

Result:

C:\repro>C:\repro\bin\release\net10.0-windows10.0.26100.0\win-x64\publish\repro.exe
0 423104
1 594008
2 1087232
3 2105616
4 5180840
5 13346200
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.Generic.Dictionary`2.CollectionsMarshalHelper.GetValueRefOrAddDefault(Dictionary`2, TKey, Boolean&) + 0x1e2
   at System.Runtime.InteropServices.ComWrappers.RcwCache.GetOrAddProxyForComInstance(IntPtr, ComWrappers.NativeObjectWrapper, Object) + 0x46
   at System.Runtime.InteropServices.ComWrappers.RegisterObjectForComInstance(IntPtr, IntPtr, Object, CreateObjectFlags, IntPtr&) + 0x75
   at System.Runtime.InteropServices.ComWrappers.CreateAndRegisterObjectForComInstance(IntPtr, IntPtr, CreateObjectFlags, Object, IntPtr&) + 0xa4
   at System.Runtime.InteropServices.ComWrappers.TryGetOrCreateObjectForComInstanceInternal(IntPtr, IntPtr, CreateObjectFlags, Object, Object, Object&) + 0x128
   at System.Runtime.InteropServices.ComWrappers.GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags) + 0x35

Metadata

Metadata

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions