[CSHARP-4314] Memory leak when closure/object is used for ClusterConfigurator Created: 08/Sep/22 Updated: 27/Oct/23 Resolved: 12/Sep/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Dusan Hudecek | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryWhen 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
Additional BackgroundI 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 |
| Comments |
| Comment by Dusan Hudecek [ 12/Sep/22 ] |
|
Hi @Boris Dogadov, now i can see that information in documentation so bug is not bug anymore. thanks for your help.
|
| Comment by Boris Dogadov [ 09/Sep/22 ] |
|
Hi dusan.hudecek01@gmail.com, thank you for your question. Yes, it is a known behavior, documented here: https://mongodb.github.io/mongo-csharp-driver/2.17/reference/driver/connecting/ |