-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWS SDK - Intermittent NullReferenceException #3625
Comments
@JamieKeeling Good morning. Thanks for opening the issue. While I try to investigate the possible root cause, could you please:
Thanks, |
Hi @ashishdhingra, thank you for reaching out.
This is a .NET 8 Web API
I'm unable to do this - the application code is commercially sensitive and removing enough would dilute the example. I can provide an anomymised model for the records if that still helps, keeping the attributes and usage intact?
Still working on this one - it's hard to reproduce the issue to generate logs of interest. I have also observed that when this issue occurs, we see errors in trying to use
We query for records as follows:
As above, if we restart the application we find query behaviors are restored and perform as expected. |
@JamieKeeling I would highly recommend adjusting how you create the In your case since you are adding builder.Services.TryAddSingleton<IDynamoDBContext>(sp =>
{
var client = sp.GetRequiredService<IAmazonDynamoDB>();
var context = new DynamoDBContext(client, new DynamoDBContextConfig
{
DisableFetchingTableMetadata = true
});
return context;
}); |
Hi @normj - thank you for the suggestion, I have since implemented this change as per the documentation. Additionally, I have included the following JSON within the
I am also validating the configuration as part of startup, ensuring all types are available:
With those changes in place I still see the failures, however I now notice a pattern: IDynamoDbContext.SaveAsync
Reviewing the stack trace against the AWS SDK source code, it appears that the IDynamoDBContext.FromDocument
Similar to the above, this also attempts to resolve I am unable to reproduce any of the presented issues locally however the The DynamoDbClient configuration for the above is as follows:
In summary, I can confirm that:
|
Describe the bug
When attempting to insert records using
IDynamoDBContext.SaveAsync
aNullReferenceException
is thrown from the AWS DynamoDB SDK.Expected Behavior
The
IDynamoDBContext.SaveAsync
call is successful and the record is created within the configured AWS DynamoDB table.Current Behavior
The following stack trace shows where the error is raised:
Reproduction Steps
Unable to reproduce locally, only where hosted.
Configuration of AWS SDK services (AWSSDK.Extensions.NETCore.Setup)
Saving the record
Note:
_dynamoTableName
is the logical id for the DynamoDB table.Additionally, we use the following logic within
Startup.cs
to ensure that the required interfaces are registered and available before marking the application as ready (letting AWS restart the task if necessary):Possible Solution
We have been unable to reproduce the issue locally, and so instead must resort to failing and creating new Fargate instances until we see evidence of the
IDynamoDBContext.SaveAsync
working as intended.Additional Information/Context
Initially we manually registered the required dependencies as follows:
This resulted in a different error message when invoking
IDynamoDBContext.SaveAsync
:As you can see from the message there's an implication that the required client isn't being injected. Our representative example purposefully validates they are available before allowing the task to respond to requests.
This in turn changes the error message from the above to the one reported within this issue.
Relatedely, we have other applications using the manual registration and are able to save records using the same functionality without issue.
AWS .NET SDK and/or Package version used
AWSSDK.Extensions.NETCore.Setup : 3.7.301
AWSSDK.DynamoDBv2 : 3.7.405.7
AWSSDK.Core : 3.7.401.1
Targeted .NET Platform
.NET 8
Operating System and version
Alpine Linux (ASP NET Docker Image)
The text was updated successfully, but these errors were encountered: