[CSHARP-3695] Unobserved task exception originating from Cluster Created: 31/May/21  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: Testing
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Mikalai Mazurenka (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Improve Testing

 Description   

The test MongoDB.Driver.Core.Connections.BinaryConnectionTests.ReceiveMessage_should_not_produce_unobserved_task_exceptions_on_fail occasionally catches an exception which does not originate from the test (Evergreen log):

[2021/05/20 22:43:53.303] [xUnit.net 00:01:03.78]     MongoDB.Driver.Core.Connections.BinaryConnectionTests.ReceiveMessage_should_not_produce_unobserved_task_exceptions_on_fail(async: False) [FAIL]
[2021/05/20 22:43:53.331]   X MongoDB.Driver.Core.Connections.BinaryConnectionTests.ReceiveMessage_should_not_produce_unobserved_task_exceptions_on_fail(async: False) [262ms]
[2021/05/20 22:43:53.331]   Error Message:
[2021/05/20 22:43:53.331]    System.Exception : unobserved
[2021/05/20 22:43:53.331] ---- System.AggregateException : 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.
[2021/05/20 22:43:53.331] -------- System.ObjectDisposedException : Cannot access a disposed object.
[2021/05/20 22:43:53.331]   Stack Trace:
[2021/05/20 22:43:53.331]      at MongoDB.Driver.Core.Connections.BinaryConnectionTests.ReceiveMessage_should_not_produce_unobserved_task_exceptions_on_fail(Boolean async) in C:\data\mci\e80b85c5dad8e7ee820d0e19a14cfc28\mongo-csharp-driver\tests\MongoDB.Driver.Core.Tests\Core\Connections\BinaryConnectionTests.cs:line 523
[2021/05/20 22:43:53.331] ----- Inner Stack Trace -----
[2021/05/20 22:43:53.331] ----- Inner Stack Trace -----
[2021/05/20 22:43:53.331]    at System.Threading.TimerQueueTimer.Change(UInt32 dueTime, UInt32 period)
[2021/05/20 22:43:53.331]    at System.Threading.Timer.Change(Int64 dueTime, Int64 period)
[2021/05/20 22:43:53.331]    at System.Threading.Timer.Change(TimeSpan dueTime, TimeSpan period)
[2021/05/20 22:43:53.331]    at MongoDB.Driver.Core.Clusters.Cluster.ExitServerSelectionWaitQueue() in C:\data\mci\e80b85c5dad8e7ee820d0e19a14cfc28\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Clusters\Cluster.cs:line 214
[2021/05/20 22:43:53.331]    at MongoDB.Driver.Core.Clusters.Cluster.SelectServerHelper.Dispose() in C:\data\mci\e80b85c5dad8e7ee820d0e19a14cfc28\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Clusters\Cluster.cs:line 462
[2021/05/20 22:43:53.331]    at MongoDB.Driver.Core.Clusters.Cluster.<SelectServerAsync>d__51.MoveNext() in C:\data\mci\e80b85c5dad8e7ee820d0e19a14cfc28\mongo-csharp-driver\src\MongoDB.Driver.Core\Core\Clusters\Cluster.cs:line 323

The reason why this exception is being caught is because the UnobservedTaskException event handler is configured on the entire AppDomain, which makes it handle all of the AppDomain unobserved exceptions. This indicates that another test is producing the unobserved task which throws an exception.

It is unclear which test exactly produced an unobserved exception, but the range can be narrowed down by researching how XUnit creates AppDomains for the test runs or running a limited group of tests with the UnobservedTaskException event handler set up.

Additionally, this case is likely to go away with CSHARP-2490: Reimplement SDAM to use a dedicated thread and follow the spec more closely, because currently an entire server monitor logic is run in a task which is not being observed: ServerMonitor.Initialize



 Comments   
Comment by Jeffrey Yemin [ 01/Jun/21 ]

Need investigation as to why an exception from another test is leaking into this one.

Perhaps a green build Friday task.

Generated at Wed Feb 07 21:46:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.