code: protected void safeClose () {
          Session closeSession = this.socketSession;
          this.socketSession = null;
  
          try {
              if (closeSession != null) {
                  //
                  // Remove from the registry first in case the close blocks for a while.  Doing so prevents additional
                  // errors logged for attempts to send to this now-defunct websocket.
                  //
                  registry.remove(this.socketSessionId);
                  closeSession.close();
              }
          } catch (IOException ioExc) {
              log.debug("io exception on safe close of session", ioExc);
          }
      }
docs: Safely close the websocket.