[JAVA-3754] Stray monitor thread left behind if authentication fails Created: 04/Jun/20 Updated: 27/Oct/23 Resolved: 08/Jun/20 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Connection Management |
| Affects Version/s: | 3.8.2, 3.12.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Gaurav Bahrani | Assignee: | Jeffrey Yemin |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MacOS |
||
| Attachments: |
|
| Description |
|
If incorrect credentials are supplied while setting up connection to replica-set, it results in stray monitor thread left behind. Since 'mongoClient' never got set, caller can not call close() to force driver to release resources. ------ ServerAddress address = new ServerAddress(host, localPort); MongoClientOptions options = try { MongoClient mongoClient = new MongoClient(address, credential, options); }catch (MongoSecurityException mse) { // handle login error }catch (MongoTimeoutException mte) { // handle timeout }catch (Exception ex) { // handle other errors } |
| Comments |
| Comment by Gaurav Bahrani [ 09/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jeff.yemin@mongodb.com Figured out the issue. It seems to be happening with 3.8.2 driver. When I upgraded to 3.12.5 version, the issue went away. Thanks for the help in diagnosing the issue. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unfortunately, I am not able to reproduce it my own testing. With a 10 second sleep after the call to close, the only threads left are:
So currently we do not have a way to proceed unless you can provide more information. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Gaurav Bahrani [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jeffery, shall we reopen this ticket? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Gaurav Bahrani [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Even with 5mins sleep stray thread keeps hanging around. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Gaurav Bahrani [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I was suspecting the same, hence tried adding 2mins sleep, but that also doesn't help. In my application, we create Mongo connections on need basis and overtime we are seeing 100s of stray threads lying around. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Try adding a Thread.sleep() after the MongoClient.close(). Some of the threads are closed asynchronously using Thread.interrupt(), so they may not have had a chance to be cleaned up by the time you check. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Gaurav Bahrani [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jeffrey here's the code
For successful run, here is the print
For failure run (bad user/password), here is the print
As you can see in the failure scenario, there is a "cluster-ClusterId" hanging around. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
gaurav-hevo the initial connections themselves all happen in background threads, so the constructor will return normally and not throw an exception. Try it, and I think you'll see that what I'm saying is correct. If I'm wrong, please provide a full program and log output demonstrating the issue that you're seeing. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Gaurav Bahrani [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jeffrey, if I instantiate MongoClient using empty argument constructor, then it will try to connect to a Mongo locally (localhost, 27017). I want to connect to a remote Mongo server, so I must pass host, port and credentials. As per documentation, there isn't a connect/open method which I could use to explicitly connect to a remote Mongo after constructing the client. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 08/Jun/20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The MongoClient constructor won't throw any exceptions after starting any threads. So you should be able to do:
and not leak any threads. |