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

Connection reset by peer

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.8.1
    • Component/s: Connectivity
    • Labels:
      None

      I am getting a "Connection reset by peer" message periodically throughout the day.  I have microservices running .net core 2.1 and .net core 2.2 and both are throwing this exception.

       

      The exception is thrown when doing simple Find queries.  I don't have any custom timeout settings applied on MongoClient to setup the connection.  I have the connection setup as a singleton to allow MongoClient to grab a connection from the connection pool it manages.

       

      Looking at .net core 2.1 issues, there is a reported defect on this as they have optimized their connection code.  I am wondering if the two are related.

      See Sockets Performance and SocketsHttpHandler

      https://devblogs.microsoft.com/dotnet/announcing-net-core-2-1-preview-2/

      Github Defect

      https://github.com/dotnet/corefx/issues/32305

      I have tried setting DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER environment variable as noted in the above links, but that does not resolve the issue.

       

      Here is the exception details:

      MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer

      at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(Int32 responseTo, CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
      at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
      at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync()

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            riaz.ahmad Riaz Ahmad
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: