Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce retry into Mongo DNS resolution #43222

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -26,6 +27,7 @@

import io.quarkus.mongodb.runtime.MongodbConfig;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.mutiny.Uni;
import io.vertx.core.dns.DnsClientOptions;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.core.dns.SrvRecord;
Expand Down Expand Up @@ -130,12 +132,21 @@ private List<String> resolveSrvRequest(final String srvHost) {
if (SRV_CACHE.containsKey(srvHost)) {
srvRecords = SRV_CACHE.get(srvHost);
} else {
srvRecords = dnsClient.resolveSRV(srvHost).invoke(new Consumer<>() {
@Override
public void accept(List<SrvRecord> srvRecords) {
SRV_CACHE.put(srvHost, srvRecords);
}
}).await().atMost(timeout);
srvRecords = Uni.createFrom().<List<SrvRecord>> deferred(
new Supplier<>() {
@Override
public Uni<? extends List<SrvRecord>> get() {
return dnsClient.resolveSRV(srvHost);
}
})
.onFailure().retry().withBackOff(Duration.ofSeconds(1)).atMost(3)
.invoke(new Consumer<>() {
@Override
public void accept(List<SrvRecord> srvRecords) {
SRV_CACHE.put(srvHost, srvRecords);
}
})
.await().atMost(timeout);
}

if (srvRecords.isEmpty()) {
Expand Down Expand Up @@ -167,12 +178,22 @@ public List<String> resolveTxtRequest(final String host) {
try {
Duration timeout = config.getOptionalValue(DNS_LOOKUP_TIMEOUT, Duration.class)
.orElse(Duration.ofSeconds(5));
return dnsClient.resolveTXT(host).invoke(new Consumer<>() {
@Override
public void accept(List<String> strings) {
TXT_CACHE.put(host, strings);
}
}).await().atMost(timeout);

return Uni.createFrom().<List<String>> deferred(
new Supplier<>() {
@Override
public Uni<? extends List<String>> get() {
return dnsClient.resolveTXT(host);
}
})
.onFailure().retry().withBackOff(Duration.ofSeconds(1)).atMost(3)
.invoke(new Consumer<>() {
@Override
public void accept(List<String> strings) {
TXT_CACHE.put(host, strings);
}
})
.await().atMost(timeout);
} catch (Throwable e) {
throw new MongoConfigurationException("Unable to look up TXT record for host " + host, e);
}
Expand Down