quarkusio/quarkus · error · MongoConfigurationException

Unable to look up SRV record for host

Error message

Unable to look up SRV record for host 

What it means

The SRV resolution path wraps the entire Vert.x DNS lookup and record-parsing sequence in a catch-all; any failure (DNS timeout, resolver error, malformed records) is converted into MongoConfigurationException("Unable to look up SRV record for host ...", cause).

Source

Thrown at extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java:155

                        .await().atMost(timeout);
            }

            if (srvRecords.isEmpty()) {
                throw new MongoConfigurationException("No SRV records available for host " + srvHost);
            }
            List<String> results = new ArrayList<>();
            for (SrvRecord srvRecord : srvRecords) {
                String resolvedHost = srvRecord.target().endsWith(".")
                        ? srvRecord.target().substring(0, srvRecord.target().length() - 1)
                        : srvRecord.target();

                var r = format("%d %d %d %s", srvRecord.priority(), srvRecord.weight(), srvRecord.port(), resolvedHost);
                results.add(r);
            }
            hosts.addAll(results);
            log.debugf("Resolved SRV records for %s: %s", srvHost, results);
        } catch (Throwable e) {
            throw new MongoConfigurationException("Unable to look up SRV record for host " + srvHost, e);
        }

        return hosts;
    }

    /*
     * A TXT record is just a string
     * We require each to be one or more query parameters for a MongoDB connection string.
     * Here we concatenate TXT records together with a '&' separator as required by connection strings
     */
    public List<String> resolveTxtRequest(final String host) {
        if (TXT_CACHE.containsKey(host)) {
            return TXT_CACHE.get(host);
        }
        try {
            Duration timeout = mongoConfig.dnsLookupTimeout();
            return Uni.createFrom().<List<String>> deferred(
                    new Supplier<>() {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Read the wrapped cause `e` to distinguish timeout vs. NXDOMAIN vs. resolver failure
  2. Fix container DNS configuration (resolv.conf, CoreDNS, VPN routes) so the SRV query can complete
  3. Increase resolution timeouts if the network is slow — check quarkus.mongodb dns timeout settings
  4. Retry the connection after the network recovers; if DNS is flaky, use explicit `quarkus.mongodb.hosts` instead of mongodb+srv://

Example fix

// before
quarkus.mongodb.connection-string=mongodb+srv://cluster0.abc123.mongodb.net/db
// after (explicit hosts, no DNS SRV dependency)
quarkus.mongodb.hosts=shard-0.abc123.mongodb.net:27017,shard-1.abc123.mongodb.net:27017
quarkus.mongodb.connection-string=mongodb://cluster0-shard-0.abc123.mongodb.net:27017/db
Defensive patterns

Strategy: retry

Validate before calling

// Probe DNS resolution before startup
try {
    InetAddress.getByName(srvHost);
} catch (UnknownHostException e) {
    throw new ConfigurationException("Cannot resolve SRV host " + srvHost + ": fix DNS first");
}

Try / catch

try {
    return mongoClients.create(name);
} catch (MongoConfigurationException e) {
    if (e.getCause() instanceof TimeoutException || e.getCause() instanceof DnsException) {
        return Retries.withMaxRetries(() -> mongoClients.create(name),
            Map.of(Retries.MAX_RETRIES, 3, Retries.DELAY, 2000));
    }
    throw e;
}

Prevention

When it happens

Trigger: resolveSrvRequest fails during the Vert.x resolver call `.await().atMost(timeout)` — e.g. DNS server unreachable, query timeout, or a Throwable thrown while parsing records.

Common situations: Corporate firewall blocking port 53; DNS timeouts under load (atMost timeout exceeded); misconfigured resolver in Kubernetes pods; transient network outages at startup when the Mongo client is first built.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/4498df9369d37562. Report an issue: GitHub.