title: How to wait for websockets to close gracefully on application shutdown?
body: <p>We have the following issue:</p>
  <p>Preconditions:</p>
  <ul>
  <li>Quarkus application received WebSockets connections</li>
  <li>Quarkus application is running in a pod (Kubernetes)</li>
  <li>The WebSockets connection is going through layers of 2 load balancers (elb, nginx) but we made sure that we increased the idle connection timeout (300s)</li>
  <li>Websocket server must wait for connection closes before the shutdown</li>
  <li>The client for the server doesn't have a reconnect mechanism</li>
  <li>we have a shutdown hook to wait for the WebSockets sessions closes</li>
  </ul>
  <p>Scenario when the pod is about to close:</p>
  <ul>
  <li>the application received a SIGTERM</li>
  <li>Sometimes some connections (but not all) closes with Reason GOING_AWAY (indicates that an endpoint is &quot;going away&quot;, such as a server going down or a browser having navigated away from a page)</li>
  </ul>
  <p>The shutdown hook:</p>
  <pre><code> void onStop(@Observes final ShutdownEvent ev) {
      long numActiveSessions = getActiveSessions();
      while (numActiveSessions &gt; 0) {
          try {
              TimeUnit.SECONDS.sleep(waitforfinished);
          } catch (InterruptedException e) {
              return;
          }
          numActiveSessions = getActiveSessions();
      }
  }
  </code></pre>
  <p>There is a better way to do this? Why we received the GOING_AWAY reason? Are quarkus closing the WebSockets when it received a SIGTERM?</p>
  <p>Update:
  example project: <a href="https://github.com/pedrolopix/quarkus-websockets-example" rel="nofollow noreferrer">https://github.com/pedrolopix/quarkus-websockets-example</a></p>