Skip to content

Commit

Permalink
Disable async Vert.x DNS resolver when for Spring Cloud Config
Browse files Browse the repository at this point in the history
 Relates to: https://groups.google.com/g/quarkus-dev/c/EJHwooQqUJE

(cherry picked from commit 75e6cfa)
  • Loading branch information
geoand authored and gsmet committed Mar 28, 2022
1 parent 53d97dc commit 759f8e2
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.spring.cloud.config.client.runtime;

import static io.vertx.core.spi.resolver.ResolverProvider.DISABLE_DNS_RESOLVER_PROP_NAME;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URI;
Expand All @@ -21,6 +23,7 @@
import io.quarkus.runtime.TlsConfig;
import io.quarkus.runtime.util.ClassPathUtils;
import io.smallrye.mutiny.Uni;
import io.vertx.core.VertxOptions;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.KeyStoreOptionsBase;
import io.vertx.core.net.PfxOptions;
Expand Down Expand Up @@ -53,10 +56,31 @@ public VertxSpringCloudConfigGateway(SpringCloudConfigClientConfig springCloudCo
throw new IllegalArgumentException("Value: '" + springCloudConfigClientConfig.url
+ "' of property 'quarkus.spring-cloud-config.url' is invalid", e);
}
this.vertx = Vertx.vertx();
this.vertx = createVertxInstance();
this.webClient = createHttpClient(vertx, springCloudConfigClientConfig, tlsConfig);
}

private Vertx createVertxInstance() {
// We must disable the async DNS resolver as it can cause issues when resolving the Vault instance.
// This is done using the DISABLE_DNS_RESOLVER_PROP_NAME system property.
// The DNS resolver used by vert.x is configured during the (synchronous) initialization.
// So, we just need to disable the async resolver around the Vert.x instance creation.
String originalValue = System.getProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
Vertx vertx;
try {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, "true");
vertx = Vertx.vertx(new VertxOptions());
} finally {
// Restore the original value
if (originalValue == null) {
System.clearProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
} else {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, originalValue);
}
}
return vertx;
}

public static WebClient createHttpClient(Vertx vertx, SpringCloudConfigClientConfig springCloudConfig,
TlsConfig tlsConfig) {

Expand Down

0 comments on commit 759f8e2

Please sign in to comment.