[CSHARP-3429] just declaring a `new MongoClient(connStr)` prevents my program from closing Created: 16/Feb/21  Updated: 28/Oct/23  Resolved: 26/Feb/21

Status: Closed
Project: C# Driver
Component/s: Internal
Affects Version/s: 2.9.0, 2.11.6
Fix Version/s: 2.12.0

Type: Bug Priority: Major - P3
Reporter: Andrew Stanton Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 1909, VS 16.8.5, RoslynPad 15.1, dotnet core 3.1, .net 5
Dell Latitude 7400. I cant type in a description, see attachment.


Attachments: PNG File image.png     PNG File image.png     PNG File image.png     File mongoClient hangs program.csx    
Issue Links:
Duplicate
duplicates CSHARP-2697 mongodb+srv connection string no long... Closed
Case:
Backwards Compatibility: Fully Compatible

 Comments   
Comment by Githook User [ 26/Feb/21 ]

Author:

{'name': 'Boris', 'email': 'boris.dogadov@mongodb.com', 'username': 'BorisDog'}

Message: CSHARP-3429: Setting DNS thread as background
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a0728a66bcbce20656d99179a61aee055ad12991

Comment by Boris Dogadov [ 25/Feb/21 ]

Hi Andrew,
Thank you for reporting this issue.
We have successfully reproduced this behavior, and will be submitting a fix soon.

Comment by Andrew Stanton [ 24/Feb/21 ]

Geez it is frustrating to not be able to add a comment. I could do it on at
least one JIRA ticket but not this one. I'm uploading the zip of the dump
file I collected originally that matches the screenshot in the other report
(
https://developer.mongodb.com/community/forums/t/simple-c-console-program-wont-close-after-var-mc-new-mongoclient-connstr/15934/3).
I dont see where I can send the password to you without exposing it, but
its <redacted>
. (if you can edit that out once you unzip that would be great, if not
there is nothing in there worth anyone's time to reverse engineer).

If you check the latest on that, another user found that this was a problem
for them with sharded clusters. Replicaset did not hang the calling program
open.

Your RoslynPad program does not compile as is, so i changed line 10 to be
`db.GetCollection...` instead of `client.GetCollection...`
[image: image.png]
And it still hangs up RoslynPad. I even tried taking all of the other
params off the connection string after the /test path and it does the same
thing.
[image: image.png]

Comment by James Kovacs [ 19/Feb/21 ]

Hi, Andrew,

Unclear why you're having problems commenting on JIRA tickets. I checked your permissions and you're part of jira-users, which has sufficient privileges to comment. The email processor got your comment to the right place. So you can use that for now.

When I tried the 2.11.6 driver (and other versions except 2.9.0) in RoslynPad 15.1, I did not need to dispose of the cluster in order for the running indicator to stop. When you create a MongoClient, background threads are spun up to monitor your cluster nodes but these will not prevent a program from exiting. Here is my complete sample app:

#r "nuget:MongoDB.Driver/2.11.6"
 
using MongoDB.Bson;
using MongoDB.Driver;
 
var client = new MongoClient("mongodb+srv://<<USER>>:<<PWD>>@<<ATLAS_CLUSTER_FQDN>>/test");
var db = client.GetDatabase("test");
var coll = client.GetCollection<BsonDocument>("coll");
foreach (var doc in coll.Find(new BsonDocument()).ToList()) {
    Console.WriteLine(doc);
}
"All done".Dump();

<<USER>>, <PWD>>, and <<ATLAS_CLUSTER_FQDN>> must be replaced with your information of course.

You mentioned that over 200 tasks are running when you examined the running tasks in Visual Studio. We use asynchronous tasks for cluster node monitoring and we would expect approximately as many tasks as you have nodes in your cluster. So 200+ awaiting tasks is rather unexpected for your simple program. The next step would be to collect a process dump for further analysis.

1. Install dotnet-dump:
dotnet tool install --global dotnet-dump
2. Launch RoslynPad.
3. Find the PID of RoslynPad.
(get-process -name RoslynPad).Id
4. Collect a process dump once :
dotnet dump collect -p <<PID>> --type Full
5. Attach all generated dump files (typically ./core_ (Linux) or ./dump_.dmp (Windows)) to this ticket.

Note that this will collect a full dump of the process including stack and heap memory. Please use a temporary password created specifically for this test to avoid revealing sensitive credentials.

We look forward to investigating this issue further with your assistance.

Sincerely,
James

Comment by Andrew Stanton [ 17/Feb/21 ]

First, thanks for reading and I apologize for not responding on the ticket,
but I dont seem to be able to type in the comments or description fields on
your JIRA system from either my work or home PC's. So I hope the email
processor can stick this on the JIRA ticket. The JIRA we use at my
workplace doesnt have an issue, so its probably account related. Anyway...

2.11.6 was the driver version I was trying to use and that doesn't shut
down. I then went to 2.0 and it worked, so I split-half until I found that
2.9.0 was the culprit. Note the "running" indicator still moving in the
screenshot.
[image: image.png]

This Roslynpad example does stop if I uncomment the cluster disposal, but
that doesnt work for the full program. I had to add an Environment.Exit(0)
to it, which is an OK workaround. There is more information in the
original report in the community forums (
https://developer.mongodb.com/community/forums/t/simple-c-console-program-wont-close-after-var-mc-new-mongoclient-connstr/15934)
from VS when I pause the program after it should have exited.
.

On Tue, Feb 16, 2021 at 6:57 PM James Kovacs (Jira) <jira@mongodb.org>

Comment by James Kovacs [ 16/Feb/21 ]

Hi, Andrew,

Thank you for reaching out to us. We understand that your provided sample program causes RoslynPad to not terminate execution on completion of the program and similar behaviour is observed in Visual Studio.

We have tested your sample program in RosalynPad with a variety of .NET/C# driver versions, including 2.8.1, 2.9.0, 2.9.1, 2.11.6, and others. The sample program only fails with 2.9.0, which suffers from a known bug CSHARP-2697 preventing connectivity using `mongodb+srv://` connection strings.

Please try another version of the driver such as 2.11.6 (latest) to verify that it works correctly with RosalynPad.

Sincerely,
James

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