From 91c96078080d2f092a011d52db651cac465061ba Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Tue, 29 Oct 2019 21:19:50 -0400 Subject: [PATCH] #9 fix race condition by grabbing lock before adding cache entry --- cellxgene_gateway/gateway.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 582702a..e219fb0 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -11,7 +11,7 @@ import datetime import os import logging -from threading import Thread +from threading import Thread, Lock import json from flask import ( @@ -168,15 +168,16 @@ def filecrawl(): rendered_html=rendered_html, ) - +entry_lock = Lock() @app.route("/view/", methods=["GET", "PUT", "POST"]) def do_view(path): dataset = get_dataset(path) file_path = get_file_path(dataset) - match = cache.check_entry(dataset) - if match is None: - uascripts = get_extra_scripts() - match = cache.create_entry(dataset, file_path, uascripts) + with entry_lock: + match = cache.check_entry(dataset) + if match is None: + uascripts = get_extra_scripts() + match = cache.create_entry(dataset, file_path, uascripts) match.timestamp = current_time_stamp()