diff --git a/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py b/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py index 1b41f0cff..a8819243b 100644 --- a/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py +++ b/monkey/monkey_island/cc/resources/agent_controls/stop_all_agents.py @@ -4,14 +4,14 @@ import flask_restful from flask import make_response, request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.resources.utils.semaphores import AGENT_KILLING_SEMAPHORE +from monkey_island.cc.resources.utils.semaphores import agent_killing_mutex from monkey_island.cc.services.infection_lifecycle import set_stop_all, should_agent_die class StopAllAgents(flask_restful.Resource): @jwt_required def post(self): - with AGENT_KILLING_SEMAPHORE: + with agent_killing_mutex: data = json.loads(request.data) if data["kill_time"]: set_stop_all(data["kill_time"]) diff --git a/monkey/monkey_island/cc/resources/monkey.py b/monkey/monkey_island/cc/resources/monkey.py index ffae35fba..ae8493398 100644 --- a/monkey/monkey_island/cc/resources/monkey.py +++ b/monkey/monkey_island/cc/resources/monkey.py @@ -8,7 +8,7 @@ from flask import request from monkey_island.cc.database import mongo from monkey_island.cc.models.monkey_ttl import create_monkey_ttl_document from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore -from monkey_island.cc.resources.utils.semaphores import AGENT_KILLING_SEMAPHORE +from monkey_island.cc.resources.utils.semaphores import agent_killing_mutex from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.edge.edge import EdgeService @@ -67,7 +67,7 @@ class Monkey(flask_restful.Resource): # Called on monkey wakeup to initialize local configuration @TestTelemStore.store_exported_telem def post(self, **kw): - with AGENT_KILLING_SEMAPHORE: + with agent_killing_mutex: monkey_json = json.loads(request.data) monkey_json["creds"] = [] monkey_json["dead"] = False diff --git a/monkey/monkey_island/cc/resources/utils/semaphores.py b/monkey/monkey_island/cc/resources/utils/semaphores.py index 97f36e441..4c9ef5ecc 100644 --- a/monkey/monkey_island/cc/resources/utils/semaphores.py +++ b/monkey/monkey_island/cc/resources/utils/semaphores.py @@ -1,5 +1,5 @@ from gevent.lock import BoundedSemaphore -# Semaphore avoids race condition between monkeys +# Mutex avoids race condition between monkeys # being marked dead and monkey waking up as alive -AGENT_KILLING_SEMAPHORE = BoundedSemaphore() +agent_killing_mutex = BoundedSemaphore()