Skip to content

Commit

Permalink
fix(vertx): VertxHttpClientFactory reuses the same Vertx instance for…
Browse files Browse the repository at this point in the history
… each VertxHttpClient instance

Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed Jan 28, 2025
1 parent ca6fa81 commit ffe667d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Bugs
* Fix #6781: Allowing ipv6 entries to work in NO_PROXY
* Fix #6709: VertxHttpClientFactory reuses the same Vertx instance for each VertxHttpClient instance

### 6.13.4 (2024-09-25)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,54 @@

public class VertxHttpClientFactory implements io.fabric8.kubernetes.client.http.HttpClient.Factory {

private static final class VertxHolder {

private static final Vertx INSTANCE = createVertxInstance();

private static synchronized 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.
final 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()
.setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(false).setClassPathResolvingEnabled(false))
.setUseDaemonThread(true));
} 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;
}
}

private final Vertx vertx;

public VertxHttpClientFactory() {
this.vertx = createVertxInstance();
this(VertxHolder.INSTANCE);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (vertx != null) {
vertx.close();
}
}));
}

public VertxHttpClientFactory(Vertx vertx) {
this.vertx = vertx;
}

@Override
public VertxHttpClientBuilder<VertxHttpClientFactory> newBuilder() {
return new VertxHttpClientBuilder<>(this, vertx);
}

private static synchronized 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.
final 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()
.setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(false).setClassPathResolvingEnabled(false)));
} 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;
}

/**
* Additional configuration to be applied to the options after the {@link Config} has been processed.
*/
Expand Down

0 comments on commit ffe667d

Please sign in to comment.