From 1d75616503584f608692e10ca7138f32b71aaead Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 31 Jan 2024 22:59:18 -0500 Subject: [PATCH] Fix unknown race condition in obtaining Result objects For unclear reasons, multiple Result objects can be created with the same test and machine, despite the ideal situation in that no machine is ever concurrently talking to the server. In the event a duplicate occurs, all future requests would have created an additional duplicate, as Django objects obtained via .get() expect EXACTLY one response. It is unclear how this race condition could have occured in practice --- OpenBench/workloads/get_workload.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OpenBench/workloads/get_workload.py b/OpenBench/workloads/get_workload.py index 32356cb..08e1d5c 100644 --- a/OpenBench/workloads/get_workload.py +++ b/OpenBench/workloads/get_workload.py @@ -42,9 +42,8 @@ def get_workload(machine): if not (test := select_workload(machine)): return {} - # Fetch or create the Result object for the test - try: result = Result.objects.get(test=test, machine=machine) - except: result = Result(test=test, machine=machine) + # Avoid creating duplicate Result objects + result, created = Result.objects.get_or_create(test=test, machine=machine) # Update the Machine's status and save everything machine.workload = test.id;