Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

Finalazier thread is blocked becasue of JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine #34

Closed drodov closed 6 years ago

drodov commented 7 years ago

Hi, @Taritsyn! First of all thanks for your great work on this project! We use JavaScriptEngineSwitcher.ChakraCore 2.3.2 with ReactJS.NET. But from time to time we are facing the issue that our azure web app crashes and doesn't response. After looking into memory dump I've found that the reason of that is that finalizer thread is blocked. It becomes blocked after trying to finalize ChakraCoreJsEngine. According to version history I found that similar issue was fixed in 2.3.2 version but looks like not completely. Could you please help with fixing this issue? Maybe something is going wrong because of using reference type objects in Finalize method. I attached a stack trace below.

This thread is waiting in a WaitOne

.NET Call Stack

[[HelperMethodFrame_1OBJ] (System.Threading.WaitHandle.WaitOneNative)] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean) mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21 mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28 mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12 JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1)+54 JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)+52 JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Dispose(Boolean)+48 JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Finalize()+1b [[DebuggerU2MCatchHandlerFrame]] [[ContextTransitionFrame]] [[GCFrame]] [[DebuggerU2MCatchHandlerFrame]]

Full Call Stack ntdll!NtWaitForMultipleObjects+c KERNELBASE!WaitForMultipleObjectsEx+10b clr!WaitForMultipleObjectsEx_SO_TOLERANT+3c clr!Thread::DoAppropriateWaitWorker+237 clr!Thread::DoAppropriateWait+64 clr!WaitHandleNative::CorWaitOneNative+163 [[HelperMethodFrame_1OBJ] (System.Threading.WaitHandle.WaitOneNative)] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean) mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21 mscorlib_ni!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)+21 mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28 mscorlib_ni!System.Threading.WaitHandle.WaitOne(Int32, Boolean)+28 mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12 mscorlib_ni!System.Threading.WaitHandle.WaitOne()+12 JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1)+54 JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)+52 JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Dispose(Boolean)+48 JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.Finalize()+1b clr!FastCallFinalize+6d clr!MethodTable::CallFinalizer+139 clr!CallFinalizer+a6 clr!FinalizerThread::FinalizeAllObjects+a6 clr!FinalizerThread::FinalizeAllObjects_Wrapper+14 clr!ManagedThreadBase_DispatchInner+71 clr!ManagedThreadBase_DispatchMiddle+7e clr!ManagedThreadBase_DispatchOuter+5b [[DebuggerU2MCatchHandlerFrame]] clr!ManagedThreadBase_DispatchInCorrectAD+15 clr!Thread::DoADCallBack+30f [[ContextTransitionFrame]] clr!ManagedThreadBase_DispatchInner+5f clr!FinalizerThread::DoOneFinalization+129 [[GCFrame]] clr!FinalizerThread::FinalizeAllObjects+a6 clr!FinalizerThread::FinalizerThreadWorker+ed clr!ManagedThreadBase_DispatchInner+71 clr!ManagedThreadBase_DispatchMiddle+7e clr!ManagedThreadBase_DispatchOuter+5b [[DebuggerU2MCatchHandlerFrame]] clr!ManagedThreadBase::FinalizerBase+33 clr!FinalizerThread::FinalizerThreadStart+d4 clr!Thread::intermediateThreadProc+55 kernel32!BaseThreadInitThunk+e ntdll!__RtlUserThreadStart+72 ntdll!_RtlUserThreadStart+1b

Taritsyn commented 7 years ago

Hello, Dmitry!

When I have free time, I will research this problem.

Have you tried to upgrade the JavaScriptEngineSwitcher.ChakraCore to the latest version?

Taritsyn commented 7 years ago

Try to upgrade to version 2.4.8. If after upgrade will encounter errors, then read the “Updating JavascriptEngineSwitcher.V8 breaks React.Net” discussion.

drodov commented 7 years ago

Thanks a lot!

drodov commented 7 years ago

Hello, @Taritsyn! We faced this issue again. We use version 2.4.8.

Taritsyn commented 7 years ago

Hello, Dmitry!

Frankly, I do not even know where else to find the cause of this error. As far as I know, this error did not occur at other users.

Try to upgrade the React.NET to version 3.1 (there are a lot of changes) and set the ChakraCoreJsEngine as default engine (see the “Registration of JS engines” section of documentation).

I also recommend to upgrade the JavaScript Engine Switcher to version 2.4.10. In this version was improved error handling and optimized memory consumption.

Taritsyn commented 6 years ago

Hello, Dmitry!

Try to upgrade to version 2.4.18.