Skip to content

Commit f8929ae

Browse files
committed
fix: crash on filecache object deletion
1 parent a0021b1 commit f8929ae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

webapp/cache.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ def save_to_file(self, key: str, value: Any):
151151
data = json.dumps(value)
152152
# Delete the file if it exists
153153
if Path(self.cache_path + "/" + key).exists():
154-
os.remove(self.cache_path + "/" + key)
154+
try:
155+
os.remove(self.cache_path + "/" + key)
156+
except FileNotFoundError:
157+
# We catch this as due to different processes potentially
158+
# accessing this method, deleting a file could face a race
159+
# condition.
160+
self.logger.info("File already removed")
155161
# Create base directory if it does not exist
156162
if not Path(self.cache_path).exists():
157163
Path(self.cache_path).mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)