Details
-
Bug
-
Resolution: Works as Designed
-
Unknown
-
None
-
None
-
None
-
None
Description
Summary
When using closure or new object and passing its method to ClusterConfigurator property it causes memory leak because every MongoClient creation leads to hidden threads being created for each client creation.
Nuget MongoDB.Driver version is 2.17.1.
How to Reproduce
- Create web application
- for each web request create new MongoClient which uses this configuration for
ClusterConfigurator property.
public class Test |
{
|
public Test() |
{
|
} public void ClusterConfiguration(ClusterBuilder b) |
{
|
}
|
}
|
|
|
...
|
|
|
var mongoConnectionUrl = new MongoUrl(mongoConnectionString); |
var mongoClientSettings =MongoClientSettings.FromUrl(mongoConnectionUrl);
|
var c = new Test(); |
mongoClientSettings.ClusterConfigurator = c.ClusterConfiguration;
|
Additional Background
I think that problem is caused with logic which uses this property to check equality of cluster keys and since we use new object every time when setting this property then equality fails and clusterKey is created every time which leads to RoundTripTimeMonitor being created every time with new thread.
After some time many threads is created and it can lead to application out of memory crash.
I understand that it is used to calculate equality but I think that simple assignment of action or method of newly created object should behave same and should not lead to different behavior which in the end leads to out of memory problem.
Developer cannot know that he can assign only action and cannot assign delegate of newly created object or closure. It is very hidden behavior which is hard to analyze.
What do you think?
I think that it is similar to issue https://jira.mongodb.org/browse/CSHARP-1947
Thanks