aws-sdk-net: Sporadic IndexOutOfRangeException when publishing to an AWS queue after updating to .NET 6 from .NET Core 3.1.
Describe the bug
After migrating to .NET 6 we started seeing the error from time to time when publishing a message to our AWS queue using the AmazonSimpleNotificationServiceClient sdk. Could it be because we are calling this in a loop ? Didn’t see any issues like this before the .NET update.
The request makes it to our queue but it fails trying to read the response.
Expected Behavior
Should be able to publish and get the response back successfully
Current Behavior
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Net.Http.Headers.HttpHeaders.ReadStoreValues[T](Span`1 values, Object storeValue, HttpHeaderParser parser, Int32& currentIndex)
at System.Net.Http.Headers.HttpHeaders.GetStoreValuesAsStringOrStringArray(HeaderDescriptor descriptor, Object sourceValues, String& singleValue, String[]& multiValue)
at System.Net.Http.Headers.HttpHeaders.GetEnumeratorCore()+MoveNext() at Amazon.Runtime.Internal.Transform.HttpClientResponseData.CopyHeaderValues(HttpResponseMessage response)
at Amazon.Runtime.Internal.Transform.HttpClientResponseData..ctor(HttpResponseMessage response, HttpClient httpClient, Boolean disposeClient)
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
Reproduction Steps
foreach (var request in requests)
{
var response = await _snsClient.PublishAsync(request);
}
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
<PackageReference Include="AWSSDK.Core" Version="3.7.12.5" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.2" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.3.77" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.2.74" />
Targeted .NET Platform
.NET 6
Operating System and version
Windows 10
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (4 by maintainers)
For anyone suddenly experiencing new errors on AWS SDK when retargeting an application from .NET Core 3.1 to .NET 6, check if you’re using an older version of the NewRelic agent on your application.
I had a similar issue with a container based .NET 6 Web API that started throwing the following exceptions as soon as it was retargeted to the newer version of the framework:
In my case the application was throwing these exceptions when calling PutObjectAsync of IAmazonS3, but I’ve seen similar reports on other AWS services as well (SQS, DynamoDB, etc), the stack trace is always identical.
The docker image for my application was changed into this:
Previously it was using version
8.37.0instead of the latest (at the time being)10.2.0, and the name of the package being used was the oldernewrelic-netcore20-agentinstead of the more recentnewrelic-dotnet-agent. I imagine that somewhere in between version8.37.0and10.2.0this issue was fixed.It is particularly tricky to pinpoint the New Relic agent as the root cause of the problem because the integration with New Relic is not affected in any way. The impact of running a .NET 6 application with an older New Relic agent could only be seen on HTTP calls to AWS in the form of exceptions, and even those point to the dotnet runtime, so there’s a lot of indirection here.
@jantranikianTAG Thanks for your response. This needs to be reviewed with the team for the workaround.