Skip to content

fix: Prevent KeyError in AWSClient on lock timeout#1380

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/aws-client-keyerror
Draft

fix: Prevent KeyError in AWSClient on lock timeout#1380
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/aws-client-keyerror

Conversation

@sentry

@sentry sentry Bot commented May 25, 2026

Copy link
Copy Markdown

This PR addresses the KeyError: 'secretsmanager' occurring in ddpui/utils/aws_client.py.

Problem:
The AWSClient._get_client method was susceptible to a KeyError when multiple concurrent requests attempted to initialize an AWS client (e.g., 'secretsmanager'). The _clients dictionary was initialized as empty. If a thread failed to acquire the service-specific lock within the 10-second timeout, it would proceed to access cls._clients[service_name] without service_name being guaranteed to exist in the dictionary, leading to a KeyError.

Solution:

  1. Pre-initialize _clients: The _clients class variable is now initialized with None values for all SUPPORTED_SERVICES. This ensures that all expected service keys are present in the dictionary from the start, preventing KeyError when attempting to access cls._clients[service_name].
  2. Fail fast on lock timeout: If threading.Lock().acquire() times out, a RuntimeError is now explicitly raised. This prevents the execution from proceeding with an uninitialized client and provides clearer error messaging.
  3. Update reset_instance: The reset_instance method now also re-initializes _clients with None values for all supported services, maintaining consistency with the class's initial state.

Fixes DALGO-BACKEND-2AJ

@sentry

sentry Bot commented May 25, 2026

Copy link
Copy Markdown
Author

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.66%. Comparing base (75cb6fd) to head (e402db4).

Files with missing lines Patch % Lines
ddpui/utils/aws_client.py 66.66% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants