fix: Prevent KeyError in AWSClient on lock timeout#1380
Draft
sentry[bot] wants to merge 1 commit into
Draft
Conversation
Author
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1380 +/- ##
=======================================
Coverage 58.66% 58.66%
=======================================
Files 132 132
Lines 15690 15690
=======================================
Hits 9205 9205
Misses 6485 6485 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the
KeyError: 'secretsmanager'occurring inddpui/utils/aws_client.py.Problem:
The
AWSClient._get_clientmethod was susceptible to aKeyErrorwhen multiple concurrent requests attempted to initialize an AWS client (e.g., 'secretsmanager'). The_clientsdictionary was initialized as empty. If a thread failed to acquire the service-specific lock within the 10-second timeout, it would proceed to accesscls._clients[service_name]withoutservice_namebeing guaranteed to exist in the dictionary, leading to aKeyError.Solution:
_clients: The_clientsclass variable is now initialized withNonevalues for allSUPPORTED_SERVICES. This ensures that all expected service keys are present in the dictionary from the start, preventingKeyErrorwhen attempting to accesscls._clients[service_name].threading.Lock().acquire()times out, aRuntimeErroris now explicitly raised. This prevents the execution from proceeding with an uninitialized client and provides clearer error messaging.reset_instance: Thereset_instancemethod now also re-initializes_clientswithNonevalues for all supported services, maintaining consistency with the class's initial state.Fixes DALGO-BACKEND-2AJ