-
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:
|
Based on the example stack trace from my previous reply I have tried to take a deeper look at this, but all avenues point to an issue with the SDK itself. With the updated DI setup where I am passing in the
This in turn invokes a call to the internal constructor, crucially creating an instance of
Subsequent calls make their way to
Finally, a call to create a
Knowing this, I have added instrumentation to our application that uses Reflection and checks whether the internal
In all instances of the error, the log references |
@JamieKeeling is right! I also have this problem for months! I have a Blazor Server application and the registration looks like this:
The issue is intermittent. I don't understand what is causing it. |
I have managed to replicate this locally using both the initial version of the application (i.e. no modernisation of DI) and also the updated and suggested improvemements within this thread. StepsInvoke a call to
This works correctly. In a subsequent HTTP request to the API we then invoke the following:
This causes the same The myObject (based on current production code, so no additional range key attributes)
|
Hello, reading through this issue right now. Thank you for providing reproduction steps above. We've also received a different customer report internally. I will post any updates I find here as well |
Thanks @peterrsongg - having posted this I spotted we've implemented the
Out of curiousity I removed it and was no longer able to reproduce the issue, leading me to believe it's responsible in some way. I'm assuming we're safe to let .NET manage these interfaces, but are you able to provide any guidance for the expected AWS usages at all? |
That is good to know that the using statement changes behavior. I want to step in a debug to see exactly what is happening before I say anything |
@JamieKeeling You are adding the |
@normj It’s configured in DI as a singleton, how is the lifetime resolved as scoped? |
@JamieKeeling Sorry I got mixed up with @sstere comment that showed it being added as scoped service. If you are adding it as a singleton then it should never be in a |
I haven't been able to reproduce it locally, with the |
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: