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

Possible bug in connection state management

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.4.4
    • Affects Version/s: 2.4.3
    • Component/s: Connectivity
    • Labels:
      None
    • Environment:
      .NET 4.6.2, Windows 10 x64

      When one of our databases fail over we sometimes get these exceptions:

      MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.InvalidOperationException: Invalid BinaryConnection state transition from 2 to Failed.
      MongoDB.Driver.Core.Connections.BinaryConnection.ConnectionFailed(Exception exception)
      MongoDB.Driver.Core.Connections.BinaryConnection.<ReceiveBufferAsync>d__51.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Connections.BinaryConnection.<ReceiveBufferAsync>d__52.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Connections.BinaryConnection.<ReceiveMessageAsync>d__54.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.<ExecuteAsync>d__11.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Connections.ConnectionInitializer.<InitializeConnectionAsync>d__3.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
         --- End of inner exception stack trace ---
      MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Servers.Server.<GetChannelAsync>d__27.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.<ExecuteAsync>d__39.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.OperationExecutor.<ExecuteWriteOperationAsync>d__3`1.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.MongoCollectionImpl`1.<ExecuteWriteOperationAsync>d__62`1.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.MongoCollectionImpl`1.<BulkWriteAsync>d__22.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      !Async.Rethrow
      MongoDB.Driver.MongoCollectionBase`1.<UpdateOneAsync>d__47.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      

      While the top-level exception (MongoConnectionException) looks good, the inner InvalidOperationException looks suspect to me.

      P.S. !Async.Rethrow is part of our diagnostics' stack trace compression, it's equivalent to

      System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: