3

Here is my database healthcheck :

@Readiness
@ApplicationScoped
@Slf4j
public class DatabaseConnectionHealthCheck implements HealthCheck {

    @Inject
    PgPool pgPool;

    @Override
    public HealthCheckResponse call() {
        final HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named("Database connection health check");

        try {
            pgPool.getConnection().await().indefinitely();
            log.info("Database Connection Health Check - Success");
            responseBuilder.up();

        } catch( CompletionException e ){
            log.info("Database Connection Health Check - Failure - Cause {}", e.getMessage());
            responseBuilder
                    .down()
                    .withData(
                            "Cause",
                            e.getMessage()
                    );
        }
        return responseBuilder.build();
    }
}

The problem is that is do .await().indefinitely() and I don't want it (io.vertx.core.VertxException: Thread blocked)

How to responseBuiler.up() in a reactive / subscribe way ?

Thanks

bdeweer
  • 135
  • 1
  • 14
  • Can you try with: ``` pgPool.getConnection() .subscribeOn(Infrastructure.getDefaultWorkerPool()) .emitOn(Infrastructure.getDefaultWorkerPool()) .await().indefinitely(); ``` The issue is that health check does not support async calls yet. – Clement Apr 30 '20 at 19:08
  • 1
    When Kubernetes invokes the health endpoint, it typically does so with a timeout. If the health endpoint doesn't respond in given time, it is considered unsuccessful. AFAIK, that timeout is typically in the order of seconds, so awaiting indefinitely makes little sense to me. I'd suggest awaiting for 1 or 2 seconds top, perhaps less. If your connection pool isn't able to give you a connection in 1 second, something has gone wrong. – Ladicek Apr 30 '20 at 22:04
  • Are you aware that there is already an health check defined on pgpool, brought by the reactive-pg-client extension ? Here it is : https://github.com/quarkusio/quarkus/blob/master/extensions/reactive-datasource/runtime/src/main/java/io/quarkus/reactive/datasource/runtime/ReactiveDatasourceHealthCheck.java – Lucas Declercq Feb 04 '21 at 09:14

0 Answers0