Sessions in clickhouse-keeper are local entity for each quorum participant but some information about session are global for the state of keeper: session_ids and corresponding ephemeral nodes. It make sense to send close requests to RAFT during server shutdown so all connected sessions will be closed properly and corresponding ephemeral nodes will be removed from state.

{
    setThreadName("KeeperReqT");
    
    RaftAppendResult prev_result = nullptr;
    
    
    KeeperStorage::RequestsForSessions prev_batch;
    while (!shutdown_called)
    {
        KeeperStorage::RequestForSession request;
        auto coordination_settings = configuration_and_settings->coordination_settings;
        uint64_t max_wait = coordination_settings->operation_timeout_ms.totalMilliseconds();
        uint64_t max_batch_size = coordination_settings->max_requests_batch_size;
        
        
        
        
        
        
        try
        {
            if (requests_queue->tryPop(request, max_wait))
            {
                CurrentMetrics::sub(CurrentMetrics::KeeperOutstandingRequets);
                if (shutdown_called)
                    break;
                KeeperStorage::RequestsForSessions current_batch;
                bool has_read_request = false;