DnsSrvRecordMonitor thread continues to run despite closing MongoClient

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Unknown
    • None
    • Affects Version/s: 4.7.0
    • Component/s: None
    • None
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      We detected a rogue thread that continues to run despite calling MongoClient.close(). The thread was detected because it repeatedly throws the following exception. I believe the thread is related to the DnsSrvRecordMonitorRunnable

       

      com.mongodb.MongoConfigurationException: Failed looking up SRV record for '_mongodb._tcp.prod.ds5xw.mongodb.net'.
      at com.mongodb.internal.dns.DefaultDnsResolver.resolveHostFromSrvRecords(DefaultDnsResolver.java:92)
      at com.mongodb.internal.connection.DefaultDnsSrvRecordMonitor$DnsSrvRecordMonitorRunnable.run(DefaultDnsSrvRecordMonitor.java:80)
      at java.base/java.lang.Thread.run(Thread.java:840)\nCaused by: com.mongodb.spi.dns.DnsWithResponseCodeException: DNS name not found [response code 3]
      at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(JndiDnsClient.java:52)
      at com.mongodb.internal.dns.DefaultDnsResolver.resolveHostFromSrvRecords(DefaultDnsResolver.java:74)
      ... 2 more\nCaused by: javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_mongodb._tcp.prod.ds5xw.mongodb.net'
      at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:664)
      at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:582)
      at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:434)
      at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:216)
      at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
      at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
      at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
      at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
      at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
      at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
      at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(JndiDnsClient.java:41)
      ... 3 more

       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Driver version: 4.7.0

      Server version: 6.0.20

      Topology: cluster

      How to Reproduce

      1. Initialize MongoClient:
      MongoClient client = initClient();

      2. issue test command:
      client.getDatabase("fivetran").runCommand(new Document("buildinfo", 1));
       
      3. Ensure the the command fails with some kind of MongoTimeoutException (not exactly sure how to reproduce this step, it consistently happens for the connection string we are trying to connect to):

      Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, srvResolutionException=com.mongodb.MongoConfigurationException: Failed looking up SRV record for '_mongodb._tcp.prod.ds5xw.mongodb.net'., servers=[] at com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:181) at com.mongodb.internal.connection.AbstractMultiServerCluster.getDescription(AbstractMultiServerCluster.java:50) at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:144) at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:101) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:291) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:183) at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:202) at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:171) at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:166) at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:156)

      4. call close() on mongoClient
      5. Observe repeated log messages com.mongodb.MongoConfigurationException: Failed looking up SRV record for '_mongodb._tcp.prod.ds5xw.mongodb.net' from the stacktrace above
       
      The expected behavior should be that all threads started by MongoClient are cleaned up properly so we should not see rogue threads such as DnsSrvRecordMonitorRunnable still running

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            Jeffrey Yemin
            Reporter:
            George Fivetran
            None
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: