The exception happens when remote host refuses the TCP connection.
Exception comes to Task.Scheduler.UnobservedException
Exception message:
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection refused ..0.3:1433) Connection refused ..0.3:1433
Stack trace:
System.AggregateException:
System.Net.Internals.SocketExceptionFactory+ExtendedSocketException:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Net.Sockets.Socket.EndConnect (System.Net.Sockets, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Net.Sockets.Socket+<>c.<ConnectAsync>b__275_0 (System.Net.Sockets, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Data.SqlClient.SNI.SNITCPHandle+<ConnectAsync>d__23.MoveNext (System.Data.SqlClient, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Data.SqlClient.SNI.SNITCPHandle+<ConnectAsync>d__23.MoveNext (System.Data.SqlClient, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Data.SqlClient.SNI.SNITCPHandle+<ConnectAsync>d__22.MoveNext (System.Data.SqlClient, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
No exceptions come to Task.Scheduler.UnobservedException
Host (useful for support):
Version: 3.0.3
Commit: c03f2fe626
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Additional context
The only workaround, I think, is to compare the stack trace at Task.Scheduler.UnobservedException event and in case it matches the pattern it can be ignored.
Hi @jinek
Please provide a repro if possible, and also try with Microsoft.Data.SqlClient once and let us know your experience.
@cheenamalhotra I'm sorry, but I don't have repro, only stack trace.
Thank you! I will try Microsoft.Data.SqlClient, but this way I can't tell if it helps, I can only tell if it does not.
@cheenamalhotra I've just fixed the configuration description. That was .net core 3.0 (i have looked at wrong container). As 3.0 is not maintained anymore, do we need to keep this issue at all?
Does this issue reproduce with netcoreapp3.1
at all?
If not, please feel free to close!
I'm closing it now. I need time to try on 3.1. If it's there, I will just re-open it.