From 38342e88da5d641fe9e09a9203c0ba1f1a212c94 Mon Sep 17 00:00:00 2001 From: Vladimir Sokolov Date: Sat, 3 Sep 2022 04:24:03 +0300 Subject: [PATCH] etcdserver: nil-logger issue fix for version 3.4 In v3.5 it is assumed that the logger should not be nil, however it is still a case in v3.4. The PR targeted to v3.5 was backported to 3.4 and that's why it's possible to get panic on nil logger in 3.4. This commit fixed this issue. Fixes #14402 Signed-off-by: Vladimir Sokolov --- etcdserver/v3_server.go | 46 +++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/etcdserver/v3_server.go b/etcdserver/v3_server.go index 30007c0079e..348d29ebcb3 100644 --- a/etcdserver/v3_server.go +++ b/etcdserver/v3_server.go @@ -779,11 +779,15 @@ func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, if len(rs.RequestCtx) == 8 { responseId = binary.BigEndian.Uint64(rs.RequestCtx) } - lg.Warn( - "ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader", - zap.Uint64("sent-request-id", requestId), - zap.Uint64("received-request-id", responseId), - ) + if lg != nil { + lg.Warn( + "ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader", + zap.Uint64("sent-request-id", requestId), + zap.Uint64("received-request-id", responseId), + ) + } else { + plog.Warningf("ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader (request ID want %d, got %d)", requestId, responseId) + } slowReadIndex.Inc() continue } @@ -794,7 +798,11 @@ func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, return 0, ErrLeaderChanged case <-firstCommitInTermNotifier: firstCommitInTermNotifier = s.FirstCommitInTermNotify() - lg.Info("first commit in current term: resending ReadIndex request") + if lg != nil { + lg.Info("first commit in current term: resending ReadIndex request") + } else { + plog.Info("first commit in current term: resending ReadIndex request") + } err := s.sendReadIndex(requestId) if err != nil { return 0, err @@ -802,11 +810,15 @@ func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, retryTimer.Reset(readIndexRetryTime) continue case <-retryTimer.C: - lg.Warn( - "waiting for ReadIndex response took too long, retrying", - zap.Uint64("sent-request-id", requestId), - zap.Duration("retry-timeout", readIndexRetryTime), - ) + if lg != nil { + lg.Warn( + "waiting for ReadIndex response took too long, retrying", + zap.Uint64("sent-request-id", requestId), + zap.Duration("retry-timeout", readIndexRetryTime), + ) + } else { + plog.Warningf("waiting for ReadIndex response took too long, retrying (sent-request-id: %d, retry-timeout: %s)", requestId, readIndexRetryTime) + } err := s.sendReadIndex(requestId) if err != nil { return 0, err @@ -814,10 +826,14 @@ func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, retryTimer.Reset(readIndexRetryTime) continue case <-errorTimer.C: - lg.Warn( - "timed out waiting for read index response (local node might have slow network)", - zap.Duration("timeout", s.Cfg.ReqTimeout()), - ) + if lg != nil { + lg.Warn( + "timed out waiting for read index response (local node might have slow network)", + zap.Duration("timeout", s.Cfg.ReqTimeout()), + ) + } else { + plog.Warningf("timed out waiting for read index response (local node might have slow network) timeout: %s", s.Cfg.ReqTimeout()) + } slowReadIndex.Inc() return 0, ErrTimeout case <-s.stopping: