aws-sdk-net: logging via AWS.Logger.Log4net.AWSAppender hangs web app
Description
Web application refuse to start after updating nuget package AWSSDK.core from 3.7.0.45 -> 3.7.1 (and anything newer). I’m using AWS.Logger.Log4net to send logs to cloud watch.
On my local dev machine I got valid credentials to access cloud watch and the sdk is complaining that I got invalid credentials. On 3.7.0.45 this seemed to be ignored and the web application was able to start and run without issues. But after updating to 3.7.1 the application is complaining on credentials and the web application hangs. I’m running the web application on IIS.
According to the logs it seem that a thread is aborted and that causes the whole web application to halt. Perhaps you can see if anything related to invalid credentials was changed between these versions that might cause the issue and also instruct me on how I can fix this issue.
Reproduction Steps
Updated nuget package AWSSDK.Core. Try to log using the appender
<appender name="AWS" type="AWS.Logger.Log4net.AWSAppender,AWS.Logger.Log4net">
<LogStreamNamePrefix>xx</LogStreamNamePrefix>
<LogGroup>xx</LogGroup>
<Region>xx</Region>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" />
</layout>
<LibraryLogFileName>c:\temp\logs\my_app_awslog.txt</LibraryLogFileName>
</appender>
Logs
Log Entry :
2022-01-05 20:05:03
:
:Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
vid Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
-------------------------------
Log Entry :
2022-01-05 20:05:03
:
:Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
vid Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid AWS.Logger.Core.AWSLoggerCore.<LogEventTransmissionSetup>d__33.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid AWS.Logger.Core.AWSLoggerCore.<Monitor>d__31.MoveNext()
-------------------------------
Log Entry :
2022-01-05 20:05:35
:
:Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
vid Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
-------------------------------
Log Entry :
2022-01-05 20:05:35
:
:Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
vid Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
vid Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid AWS.Logger.Core.AWSLoggerCore.<LogEventTransmissionSetup>d__33.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
vid AWS.Logger.Core.AWSLoggerCore.<Monitor>d__31.MoveNext()
-------------------------------
Log Entry :
1/5/2022 8:05:45 PM
:
:System.TimeoutException: Flush Timeout - ServiceURL=https://xxx.xx-1.amazonaws.com/, StreamName=, PendingMessages=2, CurrentBatch=0
-------------------------------
Log Entry :
2022-01-05 20:05:45
:
:System.Threading.ThreadAbortException: The thread was being aborted.
vid Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
vid System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
vid Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
vid Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
-------------------------------
Environment
- SDK Version:
- Package Version:
<package id="AWS.Logger.Core" version="3.0.0" targetFramework="net48" />
<package id="AWS.Logger.Log4net" version="3.2.1" targetFramework="net48" />
<package id="AWSSDK.CloudWatchLogs" version="3.7.0.25" targetFramework="net48" />
<package id="AWSSDK.Core" version="3.7.1" targetFramework="net48" />
<package id="log4net" version="2.0.12" targetFramework="net48" />
- OS Info: Windows 10
- Build Environment: Visual Studio
- Targeted .NET Platform: .net 4.8
Resolution
This is a 🐛 bug-report
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 18 (6 by maintainers)
It looks to be a race condition between the SDK trying to get the distributed credentials in a timer and both EC2InstanceMetadata and AmazonServiceClient calling into FallbackInternalConfigurationFactory and blocking each other.
Stack traces of what is running when it locks:
FallbackInternalConfigurationFactory is running Reset() while it is also having properties read and it appears to lock.
LMK if I can do anymore to help pinppoint the issue.