[SERVER-7776] Review v8 preemption mechanism Created: 27/Nov/12  Updated: 11/Jul/16  Resolved: 21/Dec/12

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 2.3.2

Type: Task Priority: Major - P3
Reporter: Ben Becker Assignee: Ben Becker
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-3481 interrupting --eval while(true){ ; } ... Closed
Related
related to SERVER-7989 v8's ContextSwitcher::PreemptionRecei... Closed
is related to SERVER-7990 StackLimitCheck::HasOverflowed should... Closed
Participants:

 Description   

Verify the __interruptSpecToIsolate and __interruptSpecToThreadId maps are populated and used correctly; specifically with regards to eval().

KillOp() needs to cleanly preempt any running script. Issues have been observed like isolates being shutdown during native function execution, which may result in trying to dereference an empty handle (e.g. SERVER-7633 and evald.js).



 Comments   
Comment by auto [ 26/Dec/12 ]

Author:

{u'date': u'2012-12-26T20:20:04Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: remove some uses of V8_SIMPLE_HEADER by moving scope init functions to ctor
Branch: master
https://github.com/mongodb/mongo/commit/6d9965560701c890081f5c982bc280100f5aae63

Comment by auto [ 25/Dec/12 ]

Author:

{u'date': u'2012-12-25T03:40:14Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: fix killop.js
Branch: master
https://github.com/mongodb/mongo/commit/13a61cb9c7ddce77b7f9aab812443802da8ee955

Comment by auto [ 25/Dec/12 ]

Author:

{u'date': u'2012-12-25T03:29:00Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: fix scoped_lock
Branch: master
https://github.com/mongodb/mongo/commit/bca5026bbecea061eb599d8345db5223b5a790c1

Comment by auto [ 24/Dec/12 ]

Author:

{u'date': u'2012-12-24T00:34:04Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: remove v8 locker preemption, thus rely on polling the stack guard's TERMINATE flag
Branch: master
https://github.com/mongodb/mongo/commit/14cf20504b6d37117dc365f24a9f0e7db22dd995

Comment by auto [ 21/Dec/12 ]

Author:

{u'date': u'2012-12-21T20:57:06Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: fix preemption mechanism, heap-allocated handles and handle scopes
Branch: master
https://github.com/mongodb/mongo/commit/510dc00e63a9e33735f1d3afe21c4e5c5cd0077b

Comment by auto [ 10/Dec/12 ]

Author:

{u'date': u'2012-12-10T21:53:38Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: remove unused array conversion
Branch: master
https://github.com/mongodb/mongo/commit/b02156f6c11d8f0e865e0a56f72c04c072fca9b9

Comment by auto [ 10/Dec/12 ]

Author:

{u'date': u'2012-12-10T21:21:31Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-7776: remove unused v8 wrapper
Branch: master
https://github.com/mongodb/mongo/commit/855059c482e9a265210f2eb60957d0c0fd0d57c3

Comment by Ben Becker [ 30/Nov/12 ]

We should remove the __interruptSpecToThreadId map as we only use the __interruptSpecToIsolate map. This is primarily for correctness, but also saves us from maintaining a second map. We should also consider making __interruptSpecToIsolate an unordered_map.

While this doesn't appear to be an issue, I did notice http://code.google.com/p/v8/issues/detail?id=708. I'm not sure if that's still an issue, but if so, the following function may kill the wrong thread, or never kill a thread:

    void V8ScriptEngine::interrupt( unsigned opSpec ) {
        v8::Locker l;
        v8Locks::InterruptLock il;
        if ( __interruptSpecToThreadId.count( opSpec ) ) {
            int thread = __interruptSpecToThreadId[ opSpec ];
            if ( thread == -2 || thread == -3) {
                // just mark as interrupted
                __interruptSpecToThreadId[ opSpec ] = -3;
                return;
            }
 
            V8::TerminateExecution( __interruptSpecToIsolate[ opSpec ] );
        }
    }

Generated at Thu Feb 08 03:15:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.