From b14fd4687c3cdb73cdb49bfca86dfdb18d3b0831 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Wed, 2 Oct 2019 16:39:59 +0300 Subject: [PATCH] Removed debug logs and made all locks private to the module --- .../cc/services/reporting/report.py | 2 -- .../report_generation_synchronisation.py | 25 ++++++------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index 1221200c4..03d0f5011 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -1,7 +1,6 @@ import functools import itertools import logging -import time import ipaddress from bson import json_util @@ -692,7 +691,6 @@ class ReportService: @staticmethod def generate_report(): - time.sleep(40) domain_issues = ReportService.get_domain_issues() issues = ReportService.get_issues() config_users = ReportService.get_config_users() diff --git a/monkey/monkey_island/cc/services/reporting/report_generation_synchronisation.py b/monkey/monkey_island/cc/services/reporting/report_generation_synchronisation.py index 1fe4d8bb8..9025ff68f 100644 --- a/monkey/monkey_island/cc/services/reporting/report_generation_synchronisation.py +++ b/monkey/monkey_island/cc/services/reporting/report_generation_synchronisation.py @@ -6,47 +6,37 @@ logger = logging.getLogger(__name__) # These are pseudo-singletons - global Locks. These locks will allow only one thread to generate a report at a time. # Report generation can be quite slow if there is a lot of data, and the UI queries the Root service often; without # the locks, these requests would accumulate, overload the server, eventually causing it to crash. -logger.debug("Initializing report generation lock.") -report_generating_lock = threading.Semaphore() +logger.debug("Initializing report generation locks.") +__report_generating_lock = threading.Semaphore() __attack_report_generating_lock = threading.Semaphore() __regular_report_generating_lock = threading.Semaphore() def safe_generate_reports(): - # Wait until report generation is available. - logger.debug("Waiting for report generation...") - # Entering the critical section. - report_generating_lock.acquire() - logger.debug("Report generation locked.") + # Entering the critical section; Wait until report generation is available. + __report_generating_lock.acquire() report = safe_generate_regular_report() attack_report = safe_generate_attack_report() # Leaving the critical section. - report_generating_lock.release() - logger.debug("Report generation released.") + __report_generating_lock.release() return report, attack_report def safe_generate_regular_report(): # Local import to avoid circular imports from monkey_island.cc.services.reporting.report import ReportService - logger.debug("Waiting for regular report generation...") __regular_report_generating_lock.acquire() - logger.debug("Regular report generation locked.") report = ReportService.generate_report() __regular_report_generating_lock.release() - logger.debug("Regular report generation released.") return report def safe_generate_attack_report(): # Local import to avoid circular imports from monkey_island.cc.services.attack.attack_report import AttackReportService - logger.debug("Waiting for attack report generation...") __attack_report_generating_lock.acquire() - logger.debug("Attack report generation locked.") attack_report = AttackReportService.generate_new_report() __attack_report_generating_lock.release() - logger.debug("Attack report generation released.") return attack_report @@ -55,9 +45,8 @@ def is_report_being_generated(): # When invoked with blocking set to false, do not block. # If a call without an argument would block, return false immediately; # otherwise, do the same thing as when called without arguments, and return true. - is_report_being_generated_right_now = not report_generating_lock.acquire(blocking=False) - logger.debug("is_report_being_generated_right_now == " + str(is_report_being_generated_right_now)) + is_report_being_generated_right_now = not __report_generating_lock.acquire(blocking=False) if not is_report_being_generated_right_now: # We're not using the critical resource; we just checked its state. - report_generating_lock.release() + __report_generating_lock.release() return is_report_being_generated_right_now