PR feedback on terminated state checking

This commit is contained in:
Chris S. Kim 2022-09-06 10:28:20 -04:00
parent ddb9375cb6
commit 953808e899

View File

@ -162,17 +162,20 @@ func (s *Server) StreamResources(stream pbpeerstream.PeerStreamService_StreamRes
return grpcstatus.Error(codes.InvalidArgument, "initial subscription for unknown PeerID: "+req.PeerID) return grpcstatus.Error(codes.InvalidArgument, "initial subscription for unknown PeerID: "+req.PeerID)
} }
if !p.IsActive() { if !p.IsActive() {
logger.Warn("peering is marked as deleted or terminated", "peer_id", req.PeerID) // If peering is terminated, then our peer sent the termination message.
term := &pbpeerstream.ReplicationMessage{ // For other non-active states, send the termination message.
Payload: &pbpeerstream.ReplicationMessage_Terminated_{ if p.State != pbpeering.PeeringState_TERMINATED {
Terminated: &pbpeerstream.ReplicationMessage_Terminated{}, term := &pbpeerstream.ReplicationMessage{
}, Payload: &pbpeerstream.ReplicationMessage_Terminated_{
} Terminated: &pbpeerstream.ReplicationMessage_Terminated{},
logTraceSend(logger, term) },
}
logTraceSend(logger, term)
// we don't care if send fails; stream will be killed by termination message or grpc error // we don't care if send fails; stream will be killed by termination message or grpc error
_ = stream.Send(term) _ = stream.Send(term)
return grpcstatus.Error(codes.FailedPrecondition, "peering is marked as deleted: "+req.PeerID) }
return grpcstatus.Error(codes.Aborted, "peering is marked as deleted: "+req.PeerID)
} }
secrets, err := s.GetStore().PeeringSecretsRead(nil, req.PeerID) secrets, err := s.GetStore().PeeringSecretsRead(nil, req.PeerID)