Code Monkey home page Code Monkey logo

Comments (4)

Susko3 avatar Susko3 commented on July 22, 2024

The bindable dictionary being bound to is updated from network requests: https://github.com/ppy/osu/blob/41c33f74f27822889290aea330ade6654eb6f5a3/osu.Game/Online/Metadata/OnlineMetadataClient.cs#L188-L199.

The underlying issue is very likely a race condition when adding new items to the bindable dictionary during the BindTo() call.
Locking on them before BindTo() will probably resolves the osu! issue.

Isolated repro (100% rate in Release configuration, Debug takes a few tries):

[Test]
public void TestThreading()
{
    var d = new BindableDictionary<int, string>();
    var underTest = new BindableDictionary<int, string>();

    var startExecution = new ManualResetEventSlim();

    Task.Factory.StartNew(() =>
    {
        startExecution.Wait(TimeSpan.FromSeconds(10));

        for (int i = 0; i < 1000; i++)
            d.Add(i, $"test {i}");
    });

    var t = Task.Factory.StartNew(() =>
    {
        startExecution.Wait(TimeSpan.FromSeconds(10));

        underTest.BindTo(d);
    });

    startExecution.Set();

    t.Wait(TimeSpan.FromSeconds(10));
}

Stack trace from test matches the sentry report:

osu.Framework.Tests.Bindables.BindableDictionaryTest.TestThreading

System.AggregateException : One or more errors occurred. (Destination array is not long enough to copy all the items in the collection. Check array index and length.)
  ----> System.ArgumentException : Destination array is not long enough to copy all the items in the collection. Check array index and length.
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
   at osu.Framework.Tests.Bindables.BindableDictionaryTest.TestThreading() in C:\...\osu-framework\osu.Framework.Tests\Bindables\BindableDictionaryTest.cs:line 1050
--ArgumentException
   at System.Collections.Generic.Dictionary`2.CopyTo(KeyValuePair`2[] array, Int32 index)
   at System.Collections.Generic.Dictionary`2.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair`2[] array, Int32 index)
   at osu.Framework.Bindables.BindableDictionary`2.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair`2[] array, Int32 arrayIndex) in C:\...\osu-framework\osu.Framework\Bindables\BindableDictionary.cs:line 249
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at osu.Framework.Bindables.BindableDictionary`2.Parse(Object input, IFormatProvider provider) in C:\...\osu-framework\osu.Framework\Bindables\BindableDictionary.cs:line 291
   at osu.Framework.Bindables.BindableDictionary`2.BindTo(BindableDictionary`2 them) in C:\...\osu-framework\osu.Framework\Bindables\BindableDictionary.cs:line 465
   at osu.Framework.Tests.Bindables.BindableDictionaryTest.<>c__DisplayClass64_0.<TestThreading>b__1() in C:\...\osu-framework\osu.Framework.Tests\Bindables\BindableDictionaryTest.cs:line 1045
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

from osu-framework.

peppy avatar peppy commented on July 22, 2024

Bindables aren't thread safe, so I'd say this is up to us to fix osu! side..

from osu-framework.

bdach avatar bdach commented on July 22, 2024

#5635 is related

from osu-framework.

peppy avatar peppy commented on July 22, 2024

#5635 is related

I'd argue it's best to just cover this in that thread, and fix the issue osu! side for this one (I'll look into it).

from osu-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.