private async Task <bool> DispatchServerWideTcpConnection(TcpConnectionOptions tcp, TcpConnectionHeaderMessage header) { tcp.Operation = header.Operation; if (tcp.Operation == TcpConnectionHeaderMessage.OperationTypes.Cluster) { ServerStore.ClusterAcceptNewConnection(tcp.Stream); return(true); } if (tcp.Operation == TcpConnectionHeaderMessage.OperationTypes.Heartbeats) { // check for the term using (_tcpContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var headerJson = await context.ParseToMemoryAsync( tcp.Stream, "maintenance-heartbeat-header", BlittableJsonDocumentBuilder.UsageMode.None, tcp.PinnedBuffer )) { var maintenanceHeader = JsonDeserializationRachis <ClusterMaintenanceSupervisor.ClusterMaintenanceConnectionHeader> .Deserialize(headerJson); if (_clusterMaintenanceWorker?.CurrentTerm > maintenanceHeader.Term) { if (_tcpLogger.IsInfoEnabled) { _tcpLogger.Info($"Request for maintenance with term {maintenanceHeader.Term} was rejected, " + $"because we are already connected to the recent leader with the term {_clusterMaintenanceWorker.CurrentTerm}"); } tcp.Dispose(); return(true); } var old = _clusterMaintenanceWorker; using (old) { _clusterMaintenanceWorker = new ClusterMaintenanceWorker(tcp, ServerStore.ServerShutdown, ServerStore, maintenanceHeader.Term); _clusterMaintenanceWorker.Start(); } return(true); } } return(false); }