code: private void releaseSession(Session session) {
      // Remove all instances of the session from the lock queue.
      queue.removeIf(lock -> lock.session.equals(session.sessionId()));
  
      // If the removed session is the current holder of the lock, nullify the lock and attempt to grant it
      // to the next waiter in the queue.
      if (lock != null && lock.session.equals(session.sessionId())) {
        lock = queue.poll();
        while (lock != null) {
          // If the waiter has a lock timer, cancel the timer.
          Scheduled timer = timers.remove(lock.index);
          if (timer != null) {
            timer.cancel();
          }
  
          // Notify the client that it has acquired the lock.
          Session lockSession = getSession(lock.session);
          if (lockSession != null && lockSession.getState().active()) {
            getSession(lock.session).accept(service -> service.locked(lock.id, lock.index));
            break;
          }
          lock = queue.poll();
        }
      }
    }
docs: Handles a session that has been closed by a client or expired by the cluster.
  <p>
  When a session is removed, if the session is the current lock holder then the lock is released and the next
  session waiting in the queue is granted the lock. Additionally, all pending lock requests for the session
  are removed from the lock queue.
  
  @param session the closed session