Skip to content

fix: Fix deadlock when snap start and using secret for api key#853

Merged
lym953 merged 2 commits intomainfrom
yiming.luo/snap-start-deadlock
Sep 19, 2025
Merged

fix: Fix deadlock when snap start and using secret for api key#853
lym953 merged 2 commits intomainfrom
yiming.luo/snap-start-deadlock

Conversation

@lym953
Copy link
Copy Markdown
Contributor

@lym953 lym953 commented Sep 18, 2025

Problem

When a Lambda (1) uses snap start, and (2) specifies Datadog API key using DD_API_KEY_SECRET_ARN, the extension will encounter a deadlock. For a RwLock, the extension first gets a read lock:

let aws_credentials_read = aws_credentials.read().await;

then tries to get a write lock:
let mut aws_credentials_write = aws_credentials.write().await;

which never finishes. This causes the function to time out.

This bug was introduced in #717.

This PR

Fix this bug by removing the RwLock usage. AwsCredential is only created and used once in resolve_secrets(), and resolve_secrets() is only called once, so there's no need to protect this struct with a lock.

Testing

Tested on a Lambda with:

  • Python 3.13 runtime
  • snap start
  • using DD_API_KEY_SECRET_ARN

Before:

  • The function timed out.
  • Data failed to be sent to Datadog.

After:

  • The function finished without timeout.
  • Data was sent to Datadog successfully.

Notes

Jira: https://datadoghq.atlassian.net/browse/SLES-2482

@lym953 lym953 force-pushed the yiming.luo/snap-start-deadlock branch from f6132a7 to bc99e51 Compare September 18, 2025 19:51
fn load_configs(start_time: Instant) -> (AwsConfig, Arc<Config>) {
// First load the AWS configuration
let aws_config = AwsConfig::from_env(start_time);
let aws_credentials = AwsCredentials::from_env();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to load credentials from main()

};

let aws_credentials_read = aws_credentials.read().await;
let mut aws_credentials = AwsCredentials::from_env();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load it as needed in resolve_secrets(), which is called lazily.

@lym953 lym953 merged commit 7466374 into main Sep 19, 2025
46 checks passed
@lym953 lym953 deleted the yiming.luo/snap-start-deadlock branch September 19, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants