[SERVER-8053] timeoutMs was never implemented in V8Scope's invoke() or exec() Created: 01/Jan/13  Updated: 11/Jul/16  Resolved: 13/Jan/13

Status: Closed
Project: Core Server
Component/s: JavaScript, MapReduce
Affects Version/s: 2.3.1
Fix Version/s: 2.4.0-rc0

Type: Bug 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

Operating System: ALL
Participants:

 Description   

Noticed after changing the following line to an massert():

https://github.com/mongodb/mongo/blob/master/src/mongo/scripting/engine_v8.cpp#L890

Needed for:

  • group() specifies a 100ms timeout when executing a trivial 'assign to global' script. I think this timeout can be safely removed. See group.cpp, lines 83, 84, 154 and 169.
  • $where specifies a 60 second timeout per document. See matcher.cpp L115 and L1173.
  • dbEval() also uses cmdLine.quota to determine if it should limit db.eval() times to 10 minutes. See dbeval.cpp L86.
  • benchRun() uses the timeout in a few places. See bench.cpp, L381, L401, L448, L480, L509, L542.


 Comments   
Comment by auto [ 11/Jan/13 ]

Author:

{u'date': u'2013-01-11T22:40:10Z', u'email': u'ben.becker@10gen.com', u'name': u'Ben Becker'}

Message: SERVER-8053: support for timeouts in V8Scope's invoke() and exec()
Branch: master
https://github.com/mongodb/mongo/commit/5053efc1043a095a013c40af1cc382a60895d4b5

Comment by Ben Becker [ 03/Jan/13 ]

The SpiderMonkey implementation used JS_SetBranchCallback to implement timeouts. I think we have two options for v8:

  • Use v8::V8::AddCallCompletedCallback() and periodically check for timeouts
  • Spawn a single thread to watch for timeouts, using a condition variable and timed wait to notify op start, op end, and timeout expiration(s). If a timeout is reached before op end, we would simply call kill() on the V8Scope.

The former approach seems simpler, but it's not clear if TerminateExecution() is safe to call from within this callback. It's also unclear if this is guaranteed to be called on a regular interval (e.g. in a tight loop).

The latter approach is still reasonably trivial to implement.

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