Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Issue: Access violation running V8 tests in Visual Studio [60]

Whenever I try to run a test under xUnit using the built in Visual Studio Test Runner (with xUnit plugin) containing the V8Runtime, I get either an AccessViolation or an SEHException. The strange thing is the exception does not occur if I debug the test (with/without break points).

Environment: Visual 2013 Update 4 Test Runner, xUnit, code to recreate:

public void TestAccessException() {
var runtime = new V8Runtime("Test Context");

Stack trace:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
---- System.Runtime.InteropServices.SEHException : External component has thrown an exception.
Result StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Microsoft.ClearScript.V8.V8Proxy.CreateImpl[T](Object[] args) in c:\dev\ClearScript\ClearScript\V8\V8Proxy.cs:line 93
at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8IsolateProxy.cs:line 70
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 204
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name) in c:\dev\ClearScript\ClearScript\V8\V8Runtime.cs:line 98
at FlowAPI.Scripting.JavascriptRunner..ctor() in c:\dev\FlowAPI\FlowAPI.Scripting\JavascriptRunner.cs:line 20
at FlowAPI.Server.Tests.Scripting.TestScripting.TestV8ScriptingMultiCall() in c:\dev\FlowAPI\FlowAPI.Server.Tests\Scripting\TestScripting.cs:line 20
----- Inner Stack Trace -----
at V8Isolate.Create(StdString* , V8IsolateConstraints* , Boolean , Int32 )
at Microsoft.ClearScript.V8.V8IsolateProxyImpl..ctor(String gcName, V8RuntimeConstraints gcConstraints, Boolean enableDebugging, Int32 debugPort) in c:\dev\clearscript\clearscript\v8\clearscriptv8\v8isolateproxyimpl.cpp:line 86

Comments: Our understanding is that it should unload everything loaded during the test run, but for some reason it fails to unload V8. Later, when another test reloads ClearScript, it has no way of knowing that V8 is already loaded and initialized. So it initializes it again, and that makes V8 panic and kill the process. This shouldn't ever happen in a normal application, and we've tried a bunch of things to work around it, but patching V8 to tolerate redundant initialization is the only thing that's worked. The next ClearScript release will do that, but in the meantime we recommend the workaround above.

Viewing all articles
Browse latest Browse all 2297