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