Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3695

Unobserved task exception originating from Cluster

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      None

      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

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            mikalai.mazurenka Mikalai Mazurenka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: