Skip to content

Commit

Permalink
Verify that run_id is a compatible ObjectdID
Browse files Browse the repository at this point in the history
closes #1996
  • Loading branch information
ppigazzini committed May 10, 2024
1 parent 7209a4c commit ef7860b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/fishtest/rundb.py
Expand Up @@ -14,6 +14,7 @@
import fishtest.stats.stat_util
from bson.binary import Binary
from bson.codec_options import CodecOptions
from bson.errors import InvalidId
from bson.objectid import ObjectId
from fishtest.actiondb import ActionDb
from fishtest.schemas import RUN_VERSION, nn_schema, pgns_schema, runs_schema
Expand Down Expand Up @@ -365,13 +366,18 @@ def exit_run(signum, frame):
signal.signal(signal.SIGTERM, exit_run)

def get_run(self, r_id):
r_id = str(r_id)
try:
r_id_obj = ObjectId(r_id)
except InvalidId:
return None

if self.is_primary_instance():
with self.run_cache_lock:
r_id = str(r_id)
if r_id in self.run_cache:
self.run_cache[r_id]["rtime"] = time.time()
return self.run_cache[r_id]["run"]
run = self.runs.find_one({"_id": ObjectId(r_id)})
run = self.runs.find_one({"_id": r_id_obj})
if run is not None:
self.run_cache[r_id] = {
"rtime": time.time(),
Expand All @@ -381,7 +387,7 @@ def get_run(self, r_id):
}
return run
else:
return self.runs.find_one({"_id": ObjectId(r_id)})
return self.runs.find_one({"_id": r_id_obj})

def start_timer(self):
self.timer = threading.Timer(1.0, self.flush_buffers)
Expand Down

0 comments on commit ef7860b

Please sign in to comment.