code: private void checkSessions() {
      long term = context.getTerm();
  
      // Iterate through all currently registered sessions.
      for (ServerSessionContext session : context.getStateMachine().executor().context().sessions().sessions.values()) {
        // If the session isn't already being unregistered by this leader and a keep-alive entry hasn't
        // been committed for the session in some time, log and commit a new UnregisterEntry.
        if (session.state() == Session.State.UNSTABLE && !session.isUnregistering()) {
          LOGGER.debug("{} - Detected expired session: {}", context.getCluster().member().address(), session.id());
  
          // Log the unregister entry, indicating that the session was explicitly unregistered by the leader.
          // This will result in state machine expire() methods being called when the entry is applied.
          final long index;
          try (UnregisterEntry entry = context.getLog().create(UnregisterEntry.class)) {
            entry.setTerm(term)
              .setSession(session.id())
              .setExpired(true)
              .setTimestamp(System.currentTimeMillis());
            index = context.getLog().append(entry);
            LOGGER.trace("{} - Appended {}", context.getCluster().member().address(), entry);
          }
  
          // Commit the unregister entry and apply it to the state machine.
          appender.appendEntries(index).whenComplete((result, error) -> {
            if (isOpen()) {
              context.getStateMachine().apply(index);
            }
          });
  
          // Mark the session as being unregistered in order to ensure this leader doesn't attempt
          // to unregister it again.
          session.unregister();
        }
      }
    }
docs: Checks to determine whether any sessions have expired.
  <p>
  Copycat allows only leaders to explicitly unregister sessions due to expiration. This ensures
  that sessions cannot be expired by lengthy election periods or other disruptions to time.
  To do so, the leader periodically iterates through registered sessions and checks for sessions
  that have been marked suspicious. The internal state machine marks sessions as suspicious when
  keep alive entries are not committed for longer than the session timeout. Once the leader marks
  a session as suspicious, it will log and replicate an {@link UnregisterEntry} to unregister the session.