diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java index d593b32ef6640..c309a4f09eaf7 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java @@ -1,11 +1,9 @@ package io.quarkus.smallrye.graphql.runtime; import java.util.Map; -import java.util.concurrent.TimeUnit; import org.jboss.logging.Logger; -import io.netty.util.concurrent.ScheduledFuture; import io.quarkus.security.identity.CurrentIdentityAssociation; import io.quarkus.vertx.http.runtime.CurrentVertxRequest; import io.quarkus.vertx.http.runtime.security.QuarkusHttpUser; @@ -13,9 +11,9 @@ import io.smallrye.graphql.websocket.GraphQLWebsocketHandler; import io.smallrye.graphql.websocket.graphqltransportws.GraphQLTransportWSSubprotocolHandler; import io.smallrye.graphql.websocket.graphqlws.GraphQLWSSubprotocolHandler; +import io.vertx.core.Handler; import io.vertx.core.http.HttpHeaders; import io.vertx.core.http.ServerWebSocket; -import io.vertx.core.net.impl.ConnectionBase; import io.vertx.ext.web.RoutingContext; /** @@ -60,27 +58,30 @@ protected void doHandle(final RoutingContext ctx) { } QuarkusHttpUser user = (QuarkusHttpUser) ctx.user(); - ScheduledFuture authExpiryFuture = null; + long cancellation = -1L; // Do not use 0, as you won't be able to distinguish between not set, and the first task Id if (user != null) { //close the connection when the identity expires Long expire = user.getSecurityIdentity().getAttribute("quarkus.identity.expire-time"); if (expire != null) { - authExpiryFuture = ((ConnectionBase) ctx.request().connection()).channel().eventLoop() - .schedule(() -> { - if (!serverWebSocket.isClosed()) { - serverWebSocket.close((short) 1008, "Authentication expired"); + cancellation = ctx.vertx().setTimer((expire * 1000) - System.currentTimeMillis(), + new Handler() { + @Override + public void handle(Long event) { + if (!serverWebSocket.isClosed()) { + serverWebSocket.close((short) 1008, "Authentication expired"); + } } - }, (expire * 1000) - System.currentTimeMillis(), TimeUnit.MILLISECONDS); + }); } } log.debugf("Starting websocket with subprotocol = %s", subprotocol); GraphQLWebsocketHandler finalHandler = handler; - ScheduledFuture finalAuthExpiryFuture = authExpiryFuture; + long finalCancellation = cancellation; serverWebSocket.closeHandler(v -> { finalHandler.onClose(); - if (finalAuthExpiryFuture != null) { - finalAuthExpiryFuture.cancel(false); + if (finalCancellation != -1) { + ctx.vertx().cancelTimer(finalCancellation); } }); serverWebSocket.endHandler(v -> finalHandler.onEnd());