Coder Social home page Coder Social logo

Concurrency Bug about nclone HOT 3 CLOSED

davisnw avatar davisnw commented on July 18, 2024
Concurrency Bug

from nclone.

Comments (3)

davisnw avatar davisnw commented on July 18, 2024

There are actually cares where it appears NClone gets stuck in an infinite loop. I'll try to create a minimal example to demonstrate the issue. I think both the NRE and infinite looping are related to the same issue of the internal dictionary not being thread-safe. I believe the issues are likely to arise when NClone is concurrently asked to clone the same type on different threads before the internal cache for that type has been fully constructed.

from nclone.

davisnw avatar davisnw commented on July 18, 2024

The below program (tested targeting .NET Framework 4.5.2 with NClone version 1.1.1 from Nuget) consistently reproduces both the NRE and the infinite looping. The NRE happens almost every time, the infinite looping less often but still frequently enough to see the issue.

using System;
using System.Linq;
using System.Threading.Tasks;

namespace NCloneBug
{
    class Program
    {
        public class ValueObject
        {
            private readonly int _blah;

            private ValueObject() : this(Int32.MinValue){}

            public ValueObject(int blah)
            {
                _blah = blah;
            }

            public static readonly ValueObject Empty = new ValueObject();
        }

        public class Entity
        {

            private ValueObject _foo1 = NClone.Clone.ObjectGraph(ValueObject.Empty);
            public ValueObject Foo1
            {
                get { return _foo1; }
                set {_foo1 = value; }
            }

            private ValueObject _foo3 = NClone.Clone.ObjectGraph(ValueObject.Empty);
            public ValueObject Foo3
            {
                get { return _foo3; }
                set { _foo3 = value; }
            }
        }
  
        static void Main(string[] args)
        {
            Parallel.ForEach(Enumerable.Repeat<Func<Entity>>(() => new Entity(), 20), x =>
            {
                try
                {
                    x();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            });
        }
    }
}

from nclone.

mijay avatar mijay commented on July 18, 2024

Thank you for reporting and fixing this one! I'll try to release a new version today.

from nclone.

Related Issues (9)

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.