spaykit
spaykit

Reputation: 121

How to force a worker thread to process ServerEndpointConfig.Configurator's 'modifyHandshake' method?

I'm modifying the handshake of Websocket by implementing ServerEndpointConfig.Configurator and overriding 'modifyHandshake', but the code is blocking and running on an IO thread, how can I force it to run on a worker thread?

'quarkus.websocket.dispatch-to-worker=true' is working only for @serverendpoint @onopen.

I tried to annotate the 'modifyHandshake' with @Blocking but still - it's running on an IO thread.

Expected behavior - modifyHandshake should be invoked on a worker thread.

Actual behavior modifyHandshake invoked on an IO thread.

How to Reproduce?

public class WebSocketEndpointConfigurator extends ServerEndpointConfig.Configurator {

  @Override 
  public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
  // executing blocking code
  Thread.sleep(3000)
  }
}

WARN [io.vertx.core.impl.BlockedThreadChecker] (vertx-blocked-thread-checker) Thread Thread[vert.x-eventloop-thread-7,5,main] has been blocked for 128597346 ms, time limit is 2000 ms: io.vertx.core.VertxException: Thread blocked

Quarkus 2.4.1.Final

Upvotes: 1

Views: 171

Answers (1)

Bentz
Bentz

Reputation: 133

i had the same issue.
i solved it by moving the code that was "blocking" from the modifyHandshake method into the onOpen method.

  • i noticed that the modifyHandshake runs on an eventloop thread
    and basically the onOpen method runs on a executor thread.
  • i moved all the data that i needed in order to run the "blocking" part of the code
    into the 'onOpen' method via the config.getUserProperties().
  • i invoked the "blocking" piece of code in the onOpen method and i didnt block any more.

hope it helps.

Upvotes: 1

Related Questions