mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-17 19:12:33 -05:00
Fixed infinite loop detection, I hope.
This commit is contained in:
parent
690fbc6919
commit
35fc5a5197
3 changed files with 12 additions and 7 deletions
|
@ -8,8 +8,8 @@ CocoClass = require 'lib/CocoClass'
|
|||
module.exports = class Angel extends CocoClass
|
||||
@nicks: ['Archer', 'Lana', 'Cyril', 'Pam', 'Cheryl', 'Woodhouse', 'Ray', 'Krieger']
|
||||
|
||||
infiniteLoopIntervalDuration: 2500 # check this often
|
||||
infiniteLoopTimeoutDuration: 7500 # wait this long between checks
|
||||
infiniteLoopIntervalDuration: 5000 # check this often
|
||||
infiniteLoopTimeoutDuration: 2500 # wait this long for a response when checking
|
||||
abortTimeoutDuration: 500 # give in-process or dying workers this long to give up
|
||||
|
||||
constructor: (@shared) ->
|
||||
|
@ -37,7 +37,11 @@ module.exports = class Angel extends CocoClass
|
|||
log: (args...) -> console.log "|#{@shared.godNick}'s #{@nick}|", args...
|
||||
|
||||
testWorker: =>
|
||||
@worker.postMessage func: 'reportIn' unless @destroyed
|
||||
return if @destroyed
|
||||
clearTimeout @condemnTimeout
|
||||
@condemnTimeout = _.delay @infinitelyLooped, @infiniteLoopTimeoutDuration
|
||||
@say "Let's give it", @infiniteLoopTimeoutDuration, "to not loop."
|
||||
@worker.postMessage func: 'reportIn'
|
||||
|
||||
onWorkerMessage: (event) =>
|
||||
return @say 'Currently aborting old work.' if @aborting and event.data.type isnt 'abort'
|
||||
|
@ -53,7 +57,6 @@ module.exports = class Angel extends CocoClass
|
|||
# We watch over the worker as it loads the world frames to make sure it doesn't infinitely loop.
|
||||
when 'start-load-frames'
|
||||
clearTimeout @condemnTimeout
|
||||
@condemnTimeout = _.delay @infinitelyLooped, @infiniteLoopTimeoutDuration
|
||||
when 'report-in'
|
||||
clearTimeout @condemnTimeout
|
||||
when 'end-load-frames'
|
||||
|
@ -117,6 +120,7 @@ module.exports = class Angel extends CocoClass
|
|||
@worker.postMessage func: 'finalizePreload'
|
||||
|
||||
infinitelyLooped: =>
|
||||
@say "On infinitely looped! Aborting?", @aborting
|
||||
return if @aborting
|
||||
problem = type: "runtime", level: "error", id: "runtime_InfiniteLoop", message: "Code never finished. It's either really slow or has an infinite loop."
|
||||
Backbone.Mediator.publish 'god:user-code-problem', problem: problem
|
||||
|
@ -134,6 +138,7 @@ module.exports = class Angel extends CocoClass
|
|||
@shared.busyAngels.push @
|
||||
@worker.postMessage func: 'runWorld', args: @work
|
||||
clearTimeout @purgatoryTimer
|
||||
@say "Infinite loop timer started at interval of", @infiniteLoopIntervalDuration
|
||||
@purgatoryTimer = setInterval @testWorker, @infiniteLoopIntervalDuration
|
||||
else
|
||||
@say "No work to do."
|
||||
|
|
|
@ -61,9 +61,9 @@ module.exports = class Simulator extends CocoClass
|
|||
@handleSingleSimulationError error
|
||||
|
||||
commenceSingleSimulation: ->
|
||||
@god.createWorld @generateSpellsObject()
|
||||
Backbone.Mediator.subscribeOnce 'god:infinite-loop', @handleSingleSimulationInfiniteLoop, @
|
||||
Backbone.Mediator.subscribeOnce 'god:goals-calculated', @processSingleGameResults, @
|
||||
@god.createWorld @generateSpellsObject()
|
||||
|
||||
handleSingleSimulationError: (error) ->
|
||||
console.error "There was an error simulating a single game!", error
|
||||
|
@ -197,9 +197,9 @@ module.exports = class Simulator extends CocoClass
|
|||
@god.setGoalManager new GoalManager(@world, @level.get 'goals')
|
||||
|
||||
commenceSimulationAndSetupCallback: ->
|
||||
@god.createWorld @generateSpellsObject()
|
||||
Backbone.Mediator.subscribeOnce 'god:infinite-loop', @onInfiniteLoop, @
|
||||
Backbone.Mediator.subscribeOnce 'god:goals-calculated', @processResults, @
|
||||
@god.createWorld @generateSpellsObject()
|
||||
|
||||
#Search for leaks, headless-client only.
|
||||
if @options.headlessClient and @options.leakTest and not @memwatch?
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"jsondiffpatch": "~0.1.5",
|
||||
"nanoscroller": "~0.8.0",
|
||||
"jquery.tablesorter": "~2.15.13",
|
||||
"treema": ">=0.0.1",
|
||||
"treema": "~0.0.8",
|
||||
"bootstrap": "~3.1.1",
|
||||
"validated-backbone-mediator": "~0.1.3",
|
||||
"jquery.browser": "~0.0.6"
|
||||
|
|
Loading…
Reference in a new issue