New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentDictionary.TryGetValue crashes with System.IndexOutOfRangeException: Arg_IndexOutOfRangeException #8866
Comments
@igor-sidorovich even though you cannot reproduce it, can you attach a snippet of code which shows more-or-less what you're doing when the crash happens? Also, please gather and post info about the crash environment(s) - Android version, locale, device(s). Lastly, could you attach full crash stack trace, with as much context as possible, that you get in the Google console? Thanks! |
@vitek-karas would you mind looking into this issue? |
@igor-sidorovich do you use custom If the problem is not with the equality comparer, the problem might be in |
, and looks like we are using default string comparer
Do we have option do not use FastMod?
|
@igor-sidorovich thanks for the additional information. I tried reproducing the exception today and I wasn't successful. I tried the running the following code on my Samsung S23, and there wasn't any exception thrown by private readonly ConcurrentDictionary<string, string> _dictionary = new();
private Thread[] _threads = new Thread[11];
private void OnCounterClicked(object sender, EventArgs e)
{
bool gotException = false;
for (int i = 1; i < _threads.Length; i++)
{
_threads[i] = new Thread(() =>
{
while (!gotException)
{
try
{
var key = GenerateRandomString(30, 80);
var value = "abc";
_dictionary.TryAdd(key, value);
_dictionary.TryGetValue(key, out _);
Interlocked.Increment(ref count);
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
gotException = true;
}
}
});
}
_threads[0] = new Thread(() =>
{
while (!gotException)
{
Device.BeginInvokeOnMainThread(() => CounterBtn.Text = $"i: {count}, dc: {_dictionary.Count}");
Thread.Sleep(100);
}
});
foreach (var thread in _threads)
{
thread.Start();
}
}
static string GenerateRandomString(int min, int max)
{
int length = Random.Shared.Next(min, max);
var sb = new System.Text.StringBuilder(length );
for (int i = 0; i < length; i++)
{
sb.Append((char)Random.Shared.Next('A', 'Z' + 1));
}
return sb.ToString();
} The OS eventually kills the app, but nothing suggests it is because of
It means that maybe this could some glitch in arm chips? But since it crashes on all those devices in the screenshot running different chips, it's probably not the problem. I think we need a repro if we want to fix this. |
I understand, but i also tried repro on different ARM phones and no any success. Do we have option do not use FastMod? |
I don't think so. But honestly, I think the chance that this is the problem is quite slim, since it happens on so many different devices and not just on some specific model. |
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
.NET 8.0.200, workload 34.0.52/8.0.100
Description
Since updating from Xamarin to .NET 8 we are getting next crashes in ConcurrentDictionary.
For me it looks like strange to have such crashes for ConcurrentDictionary.
Steps to Reproduce
Unfortuantle, i do not have repro(I tried but didn't succeed), but on Production we see such crashes.
Did you find any workaround?
No
Relevant log output
The text was updated successfully, but these errors were encountered: