This project has moved. For the latest updates, please go here.

Crash with engine Interrupt() instruction from another thread

Jul 9, 2013 at 9:03 AM
The documentation states that This method can be called safely from any thread

So I made this unit test. Unfortunately it crashes most of time with an access violation in function InternalFieldOK (v8\src\ The test conditions are ClearScript 5.3.2 or 5.3.3 with default V8 version. Release mode 32 bits.
        public virtual void TestScriptInterruptedCrash()
            var ctx = new PropertyBag();
            using (var engine = new V8ScriptEngine("CrashScript"))
                engine.AddHostObject("context", ctx);

                var startEvent = new ManualResetEventSlim(false);
                ThreadStart main = () =>
                    ctx["startEvent"] = startEvent;
                    ctx["counter"] = 0;
                        System.DateTime dtRun = System.DateTime.UtcNow;
                        engine.Execute("dummyDocument.js", @"
for (var i = 0; i < 3000000; i++ )

                    catch (Microsoft.ClearScript.ScriptInterruptedException si)

                var t = new Thread(main);


                // The thread did some work but was interrupted in the middle
                Assert.Greater(3000000, (Int32)ctx["counter"]);
                Assert.Less(0, (Int32)ctx["counter"]);
I can guess from call stack that it crashes when tring to access to the host object "startEvent"... but the v8 handles and objects are a bit cryptic to debug.

Am-I doing something wrong ? or does the script interruption disposes some ressources at the wrong time ?
Jul 9, 2013 at 1:18 PM
Hello julien_b! We have reproduced this issue and do not believe that you are doing anything wrong. We are investigating.
Jul 9, 2013 at 4:58 PM
Hi julien_b. Could you please download the latest source code and try your test again? We've posted an update that includes a potential fix and a modified version of your test. If the fix works for you, we'll release it as a new version of ClearScript. Thanks for reporting this issue!
Jul 10, 2013 at 12:20 PM
Edited Jul 10, 2013 at 12:20 PM
Hello, I applied the fix and recompiled : it works perfectly ! Thanks.