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

ObjectDisposedException on new connection

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.4
    • Component/s: Connectivity
    • None
    • Environment:
      .NET Core 2.0.0-preview2
      Linux x64
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Occasinally when querying the database, we get the following exception:

      MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.ObjectDisposedException: Cannot access a disposed object.
      Object name: 'System.Net.Sockets.Socket'.
         at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)
         at MongoDB.Driver.Core.Connections.TcpStreamFactory.ConfigureConnectedSocket(Socket socket)
         at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateNetworkStream(Socket socket)
         at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
         --- End of inner exception stack trace ---
         at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at MongoDB.Driver.Core.Servers.Server.<GetChannelAsync>d__27.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at MongoDB.Driver.Core.Operations.FindOperation`1.<ExecuteAsync>d__111.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at MongoDB.Driver.GridFS.GridFSBucket`1.<GetFileInfoByNameAsync>d__70.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
         at MongoDB.Driver.GridFS.GridFSBucket`1.<OpenDownloadStreamByNameAsync>d__29.MoveNext()
      

      The strange part about this is that according to a stack trace it should be a newly created socket.
      This might be a problem with low connection timeout (but I expect it to throw TimeoutException) and/or externally passed non-default cancellationToken, this looks like the only explanation how socket hapens to get disposed in TcpStreamFactory.ConnectAsync.

      This also might be a bug in .NET Core 2.0-preview2 (especially since it's a preview), but I don't think so, the other network-related code in the application functions normally (though it doesn't rule this out completely).
      In fact, if System.Threading.Timer had a bug that allowed it to fire after being disposed, this could lead to the described problem.

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: