Skip to content

Commit

Permalink
Reset the Apicurio registry client in dev mode and tests
Browse files Browse the repository at this point in the history
It holds a reference to Vertx, which will be closed on hot reload

Fixes quarkusio#26557
  • Loading branch information
ozangunalp committed Oct 17, 2023
1 parent 04d3a57 commit a4a6402
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.smallrye.openapi.deployment.spi.IgnoreStaticDocumentBuildItem;
Expand Down Expand Up @@ -48,7 +49,11 @@ void ignoreIncludedOpenAPIDocument(BuildProducer<IgnoreStaticDocumentBuildItem>

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client) {
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client, LaunchModeBuildItem launchMode)
throws NoSuchFieldException, IllegalAccessException {
if (launchMode.getLaunchMode().isDevOrTest()) {
client.clearHttpClient();
}
client.setup(vertx.getVertx());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.quarkus.apicurio.registry.common;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicReference;

import io.apicurio.registry.rest.client.RegistryClientFactory;
import io.apicurio.rest.client.VertxHttpClientProvider;
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Vertx;
Expand All @@ -11,4 +15,12 @@ public class ApicurioRegistryClient {
public void setup(RuntimeValue<Vertx> vertx) {
RegistryClientFactory.setProvider(new VertxHttpClientProvider(vertx.getValue()));
}

public void clearHttpClient() throws NoSuchFieldException, IllegalAccessException {
Field providerReference = ApicurioHttpClientFactory.class.getDeclaredField("providerReference");
providerReference.setAccessible(true);
AtomicReference ref = (AtomicReference) providerReference.get(ApicurioRegistryClient.class);
ref.set(null);
providerReference.setAccessible(false);
}
}

0 comments on commit a4a6402

Please sign in to comment.