title: Mongodb too many open files in system
body: <p>our software containing: </p>
  
  <p>centos, nginx, kestrel http server, dotnet core (v2.0.8) application work with mongodb (v3.6.7)</p>
  
  <p>kestrel http server sometimes stop responding, it seems that an error from mongodb driver connection like below logs on 3th line </p>
  
  <p>what is causing this problem ? </p>
  
  <p>i have configured max open files option to 640000 with this topic </p>
  
  <p><a href="https://medium.com/@mshanak/soved-dotnet-core-too-many-open-files-in-system-when-using-postgress-with-entity-framework-c6e30eeff6d1" rel="nofollow noreferrer">https://medium.com/@mshanak/soved-dotnet-core-too-many-open-files-in-system-when-using-postgress-with-entity-framework-c6e30eeff6d1</a></p>
  
  <p>but nothing fixed please can you help to solve this problem thank you all.</p>
  
  <pre><code>May 17 12:37:36 myserver[14611]: fail: Microsoft.AspNetCore.Server.Kestrel[13]
  May 17 12:37:36 myserver[14611]: Connection id "0HLDRQRA00CP4", Request id "0HLDRQRA00CP4:00000001": An unhandled exception was thrown by the application.
  May 17 12:37:36 myserver[14611]: MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---&gt; System.Net.Sockets.SocketException: Too many open files in system
  May 17 12:37:36 myserver[14611]: at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateSocket(EndPoint endPoint)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.TcpStreamFactory.&lt;CreateStreamAsync&gt;d__4.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.BinaryConnection.&lt;OpenHelperAsync&gt;d__48.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of inner exception stack trace ---
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.BinaryConnection.&lt;OpenHelperAsync&gt;d__48.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Servers.Server.&lt;GetChannelAsync&gt;d__30.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Operations.FindOperation`1.&lt;ExecuteAsync&gt;d__111.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.OperationExecutor.&lt;ExecuteReadOperationAsync&gt;d__3`1.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.MongoCollectionImpl`1.&lt;ExecuteReadOperationAsync&gt;d__83`1.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.MongoCollectionImpl`1.&lt;UsingImplicitSessionAsync&gt;d__91`1.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MongoDB.Driver.IAsyncCursorSourceExtensions.&lt;FirstOrDefaultAsync&gt;d__5`1.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MYData.UserCollection.&lt;GetByIdAsync&gt;d__2.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at MYAPI.Controllers.PostController.&lt;GetForExplore&gt;d__8.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;d__12.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;d__10.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;d__14.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&lt;InvokeNextResourceFilter&gt;d__22.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&lt;InvokeFilterPipelineAsync&gt;d__17.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&lt;InvokeAsync&gt;d__15.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Builder.RouterMiddleware.&lt;Invoke&gt;d__4.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.&lt;Invoke&gt;d__6.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.&lt;Invoke&gt;d__3.MoveNext()
  May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
  May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.&lt;ProcessRequestsAsync&gt;d__2.MoveNext()
  </code></pre>