Deadlock during jit compilation and logging

May 13, 2014 at 12:08 PM
Edited May 13, 2014 at 12:12 PM
Hi,

I'm using LZ4NET which is using LibZ. I would like to describe the situation which was very unclear and very serious.

I had problem when using it in the context of IIS and .NET 4.5 and multicore JIT compilation.
It was hard to find out what's actually going. The symptoms were that during recycling of IIS worker process under load, the new worker process hangs.

Turning the multicore JIT compilation off in IIS helped me to eliminate the problem, but not fully as I hoped.

The real cause of the problem which I then hardly found out, but could not simulate/reproduce.
To simplify the situation it is enough to describe 2 threads running simultaneously.
Thread 1:
  1. ...
  2. access to ClassA
  3. jit-compilation
  4. ...
  5. AsmZResolver.AssemblyResolver
  6. TraceEvent - wait for lock to release in Thread2
Thread 2:
  1. ...
  2. TraceEvent (this internally creates lock)
  3. access to ClassA
  4. JIT waiting for jit from Thread 1 to complete - never completes, because Thread 1 waits for Trace to release Lock
Maybe it is the common problem discussed in https://libz.codeplex.com/workitem/7

The latest version of LZ4NET now uses latest version of LibZ, so now there is the tracing turned off during AssemblyResolve event, and the problem should be solved.
The previous version of LZ4NET used the 1.0.3.3 version of the LibZ and there wasn't option to turn the tracing off.

Actually I was going to write to author to turn off the loging/tracing during AssemblyResolve event but in the meantime this was already done :-)