nhibernate race condition when loading entity

后端 未结 2 509
遥遥无期
遥遥无期 2020-12-29 10:53

I have a problem with a nhibernate race condition in my webapp.

I am aware of this happening when using older versions of log4net (should be fixed in 1.2.10), althou

2条回答
  •  星月不相逢
    2020-12-29 11:35

    The problem with solution that @APW provided is that by default, StreamWriter is not thread safe. Check it here: https://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=vs.110).aspx

    By passing "new StreamWriter" to Console.Set* you are passing non-thread safe instance. So I think it's a matter of time to see similar error again.

    Correct way would be using TextWriter.Synchronized method to wrap unsafe Stream.Null.

    using System.IO;
    ...
    var nullStream = TextWriter.Synchronized(TextWriter.Null);
    Console.SetOut(nullStream);
    Console.SetError(nullStream);
    

    UPD: Please ignore this. I have found that Console.SetOut wrapping any stream into TextWriter.Synchronized(...). Proof.

提交回复
热议问题