From 29e5dfb6313b32070377ab0037ca96eed7c5411f Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Tue, 3 Dec 2024 12:19:41 +0800 Subject: [PATCH] fix: prevent nil dereference when updating replica mode ERR longhorn/longhorn-9852 Signed-off-by: Chin-Ya Huang --- pkg/spdk/engine.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/spdk/engine.go b/pkg/spdk/engine.go index 1bc3a4f2..5a11e76d 100644 --- a/pkg/spdk/engine.go +++ b/pkg/spdk/engine.go @@ -996,8 +996,10 @@ func (e *Engine) ReplicaAdd(spdkClient *spdkclient.Client, dstReplicaName, dstRe } } if engineErr != nil || err != nil { - e.log.WithError(err).Errorf("Engine failed to start replica %s rebuilding, will mark the rebuilding replica mode from %v to ERR", dstReplicaName, e.ReplicaStatusMap[dstReplicaName].Mode) - e.ReplicaStatusMap[dstReplicaName].Mode = types.ModeERR + if e.ReplicaStatusMap[dstReplicaName] != nil && e.ReplicaStatusMap[dstReplicaName].Mode != types.ModeERR { + e.log.WithError(err).Errorf("Engine failed to start replica %s rebuilding, will mark the rebuilding replica mode from %v to ERR", dstReplicaName, e.ReplicaStatusMap[dstReplicaName].Mode) + e.ReplicaStatusMap[dstReplicaName].Mode = types.ModeERR + } updateRequired = true } }()