Skip to content

Commit

Permalink
Merge branch 'main' into rolling_patch_rfc6902
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaukov authored Dec 16, 2024
2 parents 2cdb721 + 6c7e750 commit fd557b3
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ jobs:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: Build Project
run: make install MAVEN_ARGS="${MAVEN_ARGS}"
#run: make install MAVEN_ARGS="${MAVEN_ARGS}"
run: mvn ${MAVEN_ARGS} install

- name: Check java-generator CLI
run: |
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#### _**Note**_: Breaking changes

### 7.0.1 (TBD)

#### Bugs

* Fix #6709: VertxHttpClientFactory reuses the same Vertx instance for each VertxHttpClient instance

### 7.0.0 (2024-12-03)

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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void buildAsyncReceivesMultipleMessages() throws Exception {
.always();
final CountDownLatch latch = new CountDownLatch(2);
final Set<String> messages = ConcurrentHashMap.newKeySet();
final WebSocket ws = httpClient.newWebSocketBuilder()
httpClient.newWebSocketBuilder()
.uri(URI.create(server.url("/websocket-multiple-message")))
.buildAsync(new WebSocket.Listener() {
@Override
Expand Down Expand Up @@ -157,6 +157,7 @@ void buildAsyncIncludesRequiredHeaders() throws Exception {
server.expect().withPath("/websocket-headers-test")
.andUpgradeToWebSocket()
.open()
.waitFor(50L).andEmit("OK")
.done()
.always();
httpClient.newWebSocketBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes.client.http;

import io.fabric8.kubernetes.client.RequestConfigBuilder;
import io.fabric8.mockwebserver.DefaultMockServer;
import io.fabric8.mockwebserver.http.RecordedRequest;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -161,7 +162,8 @@ public void expectContinue() throws Exception {
public void expectFailure() throws IOException, URISyntaxException {
try (final ServerSocket serverSocket = new ServerSocket(0)) {

try (HttpClient client = getHttpClientFactory().newBuilder().build()) {
try (HttpClient client = getHttpClientFactory().newBuilder()
.tag(new RequestConfigBuilder().withRequestRetryBackoffLimit(0).build()).build()) {
final URI uri = uriForPath(serverSocket, "/post-failing");
serverSocket.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes.client.http;

import io.fabric8.kubernetes.client.RequestConfigBuilder;
import io.fabric8.mockwebserver.DefaultMockServer;
import io.fabric8.mockwebserver.http.RecordedRequest;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -97,7 +98,8 @@ public void putInputStreamBody() throws Exception {
public void expectFailure() throws IOException, URISyntaxException {
try (final ServerSocket serverSocket = new ServerSocket(0)) {

try (HttpClient client = getHttpClientFactory().newBuilder().build()) {
try (HttpClient client = getHttpClientFactory().newBuilder()
.tag(new RequestConfigBuilder().withRequestRetryBackoffLimit(0).build()).build()) {
final URI uri = uriForPath(serverSocket, "/put-failing");
serverSocket.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ private void withHttp1() {
@DisabledOnOs(OS.WINDOWS)
public void http1Connections() throws Exception {
final DelayedResponseHandler handler = new DelayedResponseHandler(MAX_HTTP_1_CONNECTIONS,
exchange -> exchange.sendResponseHeaders(204, -1));
exchange -> {
exchange.sendResponseHeaders(204, -1);
exchange.close();
});
httpServer.createContext("/http", handler);
try (final HttpClient client = clientBuilder.build()) {
final Collection<CompletableFuture<HttpResponse<AsyncBody>>> asyncResponses = ConcurrentHashMap.newKeySet();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<aries-spifly.bundle.version>1.3.0</aries-spifly.bundle.version>
<asm.bundle.version>8.0.1</asm.bundle.version>
<slf4j.version>2.0.16</slf4j.version>
<log4j.version>2.24.2</log4j.version>
<log4j.version>2.24.3</log4j.version>
<lombok.version>1.18.36</lombok.version>
<commons-compress.version>1.27.1</commons-compress.version>
<commons-io.version>2.18.0</commons-io.version> <!-- Required by Gradle Testing Toolkit -->
Expand Down

0 comments on commit fd557b3

Please sign in to comment.