[CSHARP-4236] connecting to mongo instance 300+ times result with error: System.outofmemory exception Created: 28/Jun/22 Updated: 27/Oct/23 Resolved: 29/Jun/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Connectivity |
| Affects Version/s: | 2.15.0, 2.15.1, 2.16.0, 2.16.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | rgyu N/A | Assignee: | Dmitry Lukyanov (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Quarter: | FY22Q3 |
| Description |
SummaryI have a C# program, basically, it connects to all mongo instances, and get the version information. to ensure that the mongodb version is as expected. The program works smoothly for driver version 2.14.1 for long time. Recently, I upgrade Mongo C# driver version from 2.14.1 to 2.15.0 and above, and program throw error below:
processing: 328 of 452
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).2.15.0, 2.15.1, 2.16.0 and 2.16.1 work smoothly for 2.14.1 and below. How to Reproduce
List<MongoClusterInfo> MongoClusterList = SQLMonitorV3.getMongoClusterList(); Console.WriteLine("processing:" + "\t" + i.ToString() + " of " + MongoClusterList.Count.ToString()); if (cluster_type.Equals("sharding")) connString = connString.Substring(0, connString.Length - 1); } List<MongoInstanceInfo> MongoInstanceList = SQLMonitorV3.getMongoInstanceList(cluster_name); connString = connString.Substring(0, connString.Length - 1); if (!(version.Equals("4.0.19") || if (!allocator.Equals("tcmalloc")) }//end of for
Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by rgyu N/A [ 29/Jun/22 ] | ||||
|
thanks. I changed to use ClusterRegistry.Instance.UnregisterAndDisposeCluster(client.Cluster);, and observe the memory usage with Visual Studio diagnostic sessions. Now the memory usage is flat. Previsouly, it is sharp increasing. thanks again, and the problem is resolved. | ||||
| Comment by Dmitry Lukyanov (Inactive) [ 29/Jun/22 ] | ||||
|
I'm not sure what you mean by posted code above. That code is related to the legacy driver. You didn't use it initially.
this is not enough. You also should unregister disposed cluster. You should use:
we're planning to make our client disposable, but this will be a significant breaking change, so it will be done only in next major driver release, see this ticket for updates
| ||||
| Comment by rgyu N/A [ 29/Jun/22 ] | ||||
|
thank you very much for your response, It seems the application reaches the server limit. Somehow I run the application, and hit the limitation below. the default _maxServerCount is 100.
internal static MongoServer Create(MongoServerSettings settings, IOperationExecutor operationExecutor) servers which is the maximum number of servers allowed.", __maxServerCount);
I changed the program, and add the below code after each usage, the the patrol program runs fine again.
var mongourl = new MongoUrl(connString); processing code... client.Cluster.Dispose();
Better if we can have an explict Open/Close like other database client drivers though. Thank you very much for your suggestions.
| ||||
| Comment by Dmitry Lukyanov (Inactive) [ 28/Jun/22 ] | ||||
|
Hey rgyu@trip.com, I cannot reproduce this issue on my windows x64 machine. Here some notes that might bring some light on your issue.
|