Skip to content

Commit 433bbae

Browse files
authored
fix(athena): ensure thread safety when reading local Athena cache (#3137)
Wrapped the loop in `_LocalMetadataCacheManager.get_queries` with a lock to ensure thread safety when accessing the cache. This prevents potential race conditions in multithreaded environments.
1 parent c83ab37 commit 433bbae

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

awswrangler/athena/_cache.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def sorted_successful_generator(self) -> list["QueryExecutionTypeDef"]:
7373
Returns successful DDL and DML queries sorted by query completion time.
7474
"""
7575
filtered: list["QueryExecutionTypeDef"] = []
76-
for query in self._cache.values():
77-
if (query["Status"].get("State") == "SUCCEEDED") and (query.get("StatementType") in ["DDL", "DML"]):
78-
filtered.append(query)
76+
with self._lock:
77+
for query in self._cache.values():
78+
if (query["Status"].get("State") == "SUCCEEDED") and (query.get("StatementType") in ["DDL", "DML"]):
79+
filtered.append(query)
7980
return sorted(filtered, key=lambda e: str(e["Status"]["CompletionDateTime"]), reverse=True)
8081

8182
def __contains__(self, key: str) -> bool:

0 commit comments

Comments
 (0)