-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClearScript V8 "Cannot pass a GCHandle across AppDomains" System.ArgumentException #208
Comments
Hi @xecrets, Thanks for reporting this. The issue affects applications that utilize multiple application domains in a single process. We've reproduced it and are investigating a fix. Out of curiosity, are you using application domains directly, or is it a feature of your hosting environment – perhaps IIS? Thanks! |
Hi! Thanks for quick response. We're not using app domains explicitly. It's an ASP.NET application, and ASP.NET does use app domains. I checked a recent dump, and we appear to have 4 active app domains under normal operations. "System Domain", "Shared Domain", "Default Domain" and the actual web application domain. If some third party library or extension is creating other app domains I am not aware of it, but it's not impossible of course. ASP.NET will create a new application domain within the same hosting worker process (w3wp.exe) when a configuration change is detected, such as an updated assembly in the bin folder or an edit is made to a web.config file etc. However, as far as I am aware of this is not what's happening in this case, I'm only mentioning this to note that it's perfectly normal for an ASP.NET application to have multiple app domains running simultaneously at least for a short time. From the stack trace it appears that the crash is happening when executing a finalizer, so I'm guessing the intermittent behavior stems from the situation and timing when the garbage collection is run. |
Hi @xecrets, It isn't a timing issue. It's an interesting bug that has to do with native-to-managed method invocation. ClearScript's managed code constructs an array of function pointers for this purpose, which the native code stores in a global variable. It turns out that these pointers are specific to the domain that created them. Each one points at a "thunk" that re-enters the domain before invoking the target. With multiple domains there are multiple pointers for the same target, so a single global variable is no longer sufficient. Our next RC will include a fix for this issue. Hopefully Andrey can provide another JavaScriptEngineSwitcher build for you to test against. Thanks again for reporting this! |
OK. As soon as a new version is available, then I will definitely make new packages. |
Added support of the Microsoft ClearScript.V8 version 7.0 RC4 in the JavaScript Engine Switcher version 3.8.3. |
Hi @xecrets, If you get a chance to test it, please let us know if the JavaScript Engine Switcher update fixes your issue. Thanks! |
Hi! I've waited a few days for the code to run and restart a number of times, but I'm now happy to report that we've seen no more "Cannot pass a GCHandle across AppDomains" errors since upgrading. Thanks for fast and accurate work! |
ClearScript 7.0 includes the fix. Thank you! |
Hi,
I have an application that has been stable for several years using ChakraCore.
I've recently switched to using ClearScript.V8 RC 3 via JavaScriptEngineSwitcher
JavaScriptEngineSwitcher.Core v3.3.0
JavaScriptEngineSwitcher.V8 v3.8.2
JavaScriptEngineSwitcher.V8.Native.win-x64 v3.8.2
However, I'm now seeing intermittent crashes of the worker process:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/2/ROOT
Process ID: 3416
Exception: System.ArgumentException
Message: Cannot pass a GCHandle across AppDomains.
Parameter name: handle
StackTrace: at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyManaged.GetAllCachedV8Objects(IntPtr pCache, Ptr pV8ObjectPtrs)
at Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative.Impl64.V8Entity_DestroyHandle(Handle hEntity)
at Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative.Impl64.Microsoft.ClearScript.V8.SplitProxy.IV8SplitProxyNative.V8Entity_DestroyHandle(Handle hEntity)
at Microsoft.ClearScript.V8.SplitProxy.V8EntityHolder.Destroy(V8EntityHolder& holder)
at Microsoft.ClearScript.V8.SplitProxy.V8ContextProxyImpl.Finalize()
I've been in contact also with the author of JavaScriptEngineSwitcher, and he believes the issue to reside in the ClearScript library.
The text was updated successfully, but these errors were encountered: