Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Crash with engine Interrupt() instruction from another thread

0
0
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\api.cc). The test conditions are ClearScript 5.3.2 or 5.3.3 with default V8 version. Release mode 32 bits.
        [Test]
        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;
                    try
                    {
                        System.DateTime dtRun = System.DateTime.UtcNow;
                        engine.Execute("dummyDocument.js", @"
for (var i = 0; i < 3000000; i++ )
{
    context.counter++;
    context.startEvent.Set();
}

");
                        Assert.Inconclusive();
                    }
                    catch (Microsoft.ClearScript.ScriptInterruptedException si)
                    {
                        Assert.That(si.Message.Contains("interrupted"));
                    }
                };

                var t = new Thread(main);
                t.Start();
                Assert.That(startEvent.Wait(10000));
                engine.Interrupt();

                t.Join();

                // 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 ?

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images