Description
Describe the bug
While doing research into publishing a .NET 8 application using native AoT to EKS, I found at deploy-time that the application would fail on a code path we have in an internal library where the AWS SDK would attempt to get credentials using STS. The exception would be the following:
Unhandled Exception: Amazon.RuntimeDependencies.MissingRuntimeDependencyException: Operation failed because of a missing runtime dependency. In Native AOT builds runtime dependencies can not be dynamically loaded from assembles. Instead the runtime dependency needs to be explicitly registered. To complete this operation register an instance of Amazon.SecurityToken.AmazonSecurityTokenServiceClient from package AWSSDK.SecurityToken using the operation Amazon.RuntimeDependencies.GlobalRuntimeDependencyRegistry.Instance.RegisterSecurityTokenServiceClient.
I added the code mentioned to the application and redeployed. At this point it appeared to no longer be responding and crash-looping.
Through various trial and error, I've distilled the problematic code path down to the code snippet below.
My hunch is that the code path is somehow re-entrantly trying to access this lock, causing it to block indefinitely:
That's just a hunch - the issue could be somewhere completely different, but it's the first bit of synchronization I could find on the method call that is blocking. It also blocks using the synchronous version, GetCredentials()
, so I'm pretty sure it's not something to do with sync-over-async.
The code appears to deadlock regardless of whether native AoT is actually used at runtime or not.
Expected Behavior
The operation does not block.
With the repro, the following messages should be printed to the console:
GlobalRuntimeDependencyRegistry.RegisterSecurityTokenServiceClient()
AssumeRoleWithWebIdentityCredentials.FromEnvironmentVariables()
AssumeRoleWithWebIdentityCredentials.GetCredentialsAsync()
Credentials obtained
Current Behavior
The application blocks on the call to AssumeRoleWithWebIdentityCredentials.GetCredentialsAsync()
.
GlobalRuntimeDependencyRegistry.RegisterSecurityTokenServiceClient()
AssumeRoleWithWebIdentityCredentials.FromEnvironmentVariables()
AssumeRoleWithWebIdentityCredentials.GetCredentialsAsync()
Reproduction Steps
Run the following code within EKS where the instance credentials are available.
using Amazon.Runtime;
using Amazon.RuntimeDependencies;
using Amazon.SecurityToken;
Console.WriteLine("GlobalRuntimeDependencyRegistry.RegisterSecurityTokenServiceClient()");
GlobalRuntimeDependencyRegistry.Instance.RegisterSecurityTokenServiceClient(
(_) =>
new AmazonSecurityTokenServiceClient());
Console.WriteLine("AssumeRoleWithWebIdentityCredentials.FromEnvironmentVariables()");
var credentials = AssumeRoleWithWebIdentityCredentials.FromEnvironmentVariables();
Console.WriteLine("AssumeRoleWithWebIdentityCredentials.GetCredentialsAsync()");
_ = await credentials.GetCredentialsAsync();
Console.WriteLine("Credentials obtained");
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
AWSSDK.SecurityToken 3.7.300.38
Targeted .NET Platform
.NET 8
Operating System and version
Ubuntu 22.04.3 LTS