[CSHARP-2272] too many open files in system socket connection exception Created: 17/May/18  Updated: 29/Apr/19  Resolved: 29/Apr/19

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: cihan kaya Assignee: Wan Bachtiar
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CDRIVER-2652 too many open files in system socket ... Closed

 Comments   
Comment by Wan Bachtiar [ 04/Feb/19 ]

System.Net.Sockets.SocketException: Too many open files in system

Hi Cihan,
How do you create MongoClient instance within your application ?

Typically you only create one MongoClient instance for a given cluster and use it across your application. Creating multiple MongoClients will, however, still share the same pool of connections if and only if the MongoClientSettings are identical. However there are some conditions under which the MongoClient instances are unable to determine that they can share a connection pool, and if that's the case then each MongoClient instance will have its own connection pool which might be a possible explanation for this error.

Could you also provide the MongoDB C# driver version that you're using ?

Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the driver, please post a question on mongodb-user group with relevant the information.

Regards,
Wan.

Comment by Jeremy Mikola [ 17/May/18 ]

khancyai: You originally opened this in the CDRIVER project, which is for the C driver. It appears you're using the C# driver, so I've moved this over to the CSHARP project. For future reference, the MongoDB Drivers Ecosystem page has links to the appropriate JIRA projects for each language.

Comment by cihan kaya [ 17/May/18 ]

our software containing:

centos, nginx, kestrel http server, dotnet core (v2.0.8) application work with mongodb (v3.6.7)

kestrel http server sometimes stop responding, it seems that an error from mongodb driver connection like below logs on 3th line

what is causing this problem ?

i have configured max open files option to 640000 with this topic

https://medium.com/@mshanak/soved-dotnet-core-too-many-open-files-in-system-when-using-postgress-with-entity-framework-c6e30eeff6d1

but nothing fixed please can you help to solve this problem thank you all.
 
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. ---> System.Net.Sockets.SocketException: Too many open files in systemMay 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.<CreateStreamAsync>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.<OpenHelperAsync>d48.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.<OpenHelperAsync>d48.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.<GetChannelAsync>d30.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.<ExecuteAsync>d111.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.<ExecuteReadOperationAsync>d3`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.<ExecuteReadOperationAsync>d83`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.<UsingImplicitSessionAsync>d91`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.<FirstOrDefaultAsync>d5`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.<GetByIdAsync>d2.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.<GetForExplore>d8.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.<InvokeActionMethodAsync>d12.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.<InvokeNextActionFilterAsync>d10.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& next, Scope& scope, Object& state, Boolean& isCompleted)May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d14.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.<InvokeNextResourceFilter>d22.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& next, Scope& scope, Object& state, Boolean& isCompleted)May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d17.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.<InvokeAsync>d15.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.<Invoke>d4.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.<Invoke>d6.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.<Invoke>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.Se

Generated at Wed Feb 07 21:42:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.