ClearScript: Intermittent crash on 32-bit Windows during V8 background work

We use the V8 ClearScript engine (currently 7.2.1) to execute js code and hand in host objects implemented in C#.

We face seldom crashes which result in the stack trace I show at the end of this post.

With some debugging we think that our way to add host objects might cause a problem, that the .Net garbage collection might remove objects which are still used in the V8 engine. Some pseudo code:

— sample code — V8ScriptEngine engine = runtime.CreateScriptEngine(“ScriptEngine”, flags, debugPort); engine.AddHostObject(“someHost”, new OurHostObject()); engine.Evaluate(…);

Notice that we do not reference the object created with new OurHostObject() in our code at any later point. Debugging into the v8 shows that the host objects are stored:

private readonly ConditionalWeakTable<object, List<WeakReference>> hostObjectHostItemCache;

So it seems that .Net runtime does not know that the host object should be kept alive.

Could our seldom crashes be caused because of the WeakReference List?

We currently added code to keep our host objects in a List of our own, to make sure the objects are referenced and are kept alive. No crashes in the last 3 days.

Shouldn’t the V8 engine keep “full” references to the host objects? Is there a reason to keep only weak refs?

Regards Sven

— call stack from crash —

Managed Exception = System.AccessViolationException:Attempted to read or write protected memory. This is often an indication that other memory is corrupt. CallStack - Managed Exception

 Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative+Impl_Windows_X86.NativeCallback_Invoke(Handle)
 Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative+Impl_Windows_X86.Microsoft.ClearScript.V8.SplitProxy.IV8SplitProxyNative.NativeCallback_Invoke(Handle)
 Microsoft.ClearScript.V8.SplitProxy.NativeCallbackImpl.<Invoke>b__4_0(Microsoft.ClearScript.V8.SplitProxy.IV8SplitProxyNative)
 Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative.InvokeNoThrow(System.Action`1<Microsoft.ClearScript.V8.SplitProxy.IV8SplitProxyNative>)
 Microsoft.ClearScript.V8.SplitProxy.NativeCallbackImpl.Invoke()
 Microsoft.ClearScript.Util.MiscHelpers.Try(System.Action)
 Microsoft.ClearScript.Util.MiscHelpers+<>c__DisplayClass33_0.<QueueNativeCallback>b__0(System.Object)
 System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
 System.Threading.ThreadPoolWorkQueue.Dispatch()
 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18

Commits related to this issue

Most upvoted comments

Quick update: no v8 crash the last 9 days, since we switched the App Service to 64-bit.

Great support!

Our internal tests with our .Net code in 64-bit App Services showed no problems so far. Plan to switch to x64 on the App Service which “crashes most reliable” on the coming weekend.

Thank you 😃

Thank you for your analysis! That was fast 😃

I switched a test environments App Service to 64 bit and see how our tests behave with the platform change.

Any idea when the next version of ClearScript with disabled Fast TLS / background work could be available?

On its way. Thank you!

Yes, we enabled crash monitoring on the App Service which crashed regularily.

I will ask internally if I can share the dump. We have 5 dmp files between 550 and 870MB - maybe we can arrange to share the 550MB one. Thanks for the offer!

We use version 7.2.0.