[CSHARP-3102] Memory leak related to heartbeat when connecting to Atlas clusters Created: 13/May/20 Updated: 28/Oct/23 Resolved: 29/Oct/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Connectivity |
| Affects Version/s: | None |
| Fix Version/s: | 2.12.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alejandro Villarreal | Assignee: | Mikalai Mazurenka (Inactive) |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
We're seeing an issue when connecting to an Atlas cluster with version 2.10.4 of the driver. When the connection cannot be established (e.g. the client IP is not in Atlas' whitelist), the heartbeat on the client keeps running, and every time it executes it creates instances of MongoConnectionException that are never collected, causing a memory leak. I was not able to reproduce the problem connecting to a local standalone instance nor a local replica set. The only obvious difference between my local replica set and Atlas is that the local one does not use SSL. A trivial example that does nothing but connect to the cluster (when the client IP is not whitelisted), reproduces this problem:
The program memory slowly but steadily increases, and snapshots of the memory heap show that more and more instances of MongoConnectionException are accumulating every time. Changing the heartbeat frequency has the impact you'd expect on the memory growth rate. I'm not an expert interpreting Visual Studio's debugging info about memory, but two things caught my eye in the screenshot below: the "Cycle Detected" message (a circular reference sounds like it could be preventing the exceptions from being collected), and seeing "TaskExceptionHolder" in there, which makes me think that there's a task somewhere that's throwing an exception but is not being observed (i.e. awaited), so the exceptions are never thrown and just pile up in unreferenced tasks.
This might be related to CSHARP-2490. |
| Comments |
| Comment by Githook User [ 29/Oct/20 ] |
|
Author: {'name': 'Mikalai Mazurenka', 'email': 'mikalai.mazurenka@mongodb.com', 'username': 'MikalaiMazurenka'}Message: |