Fix retryKeepAlive assertion panic (#24667)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/24682/head
congqixia 2023-06-07 10:08:36 +08:00 committed by GitHub
parent f97127ae55
commit d0c2fa5d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -794,7 +794,7 @@ func (s *Session) LivenessCheck(ctx context.Context, callback func()) {
case mvccpb.PUT:
log.Info("register session success", zap.String("role", s.ServerName), zap.String("key", string(event.Kv.Key)))
case mvccpb.DELETE:
if s.retryKeepAlive.Load().(bool) {
if s.isRetryingKeepAlive() {
log.Info("session key is deleted during re register, ignore this DELETE event", zap.String("role", s.ServerName), zap.String("key", string(event.Kv.Key)))
continue
}
@ -873,6 +873,14 @@ func (s *Session) SetEnableRetryKeepAlive(enable bool) {
s.enableRetryKeepAlive = enable
}
func (s *Session) isRetryingKeepAlive() bool {
v, ok := s.retryKeepAlive.Load().(bool)
if !ok {
return false
}
return v
}
func (s *Session) safeCloseLiveCh() {
s.liveChOnce.Do(func() {
close(s.liveCh)

View File

@ -797,6 +797,29 @@ func (s *SessionSuite) TestDisconnected() {
}
}
func (s *SessionSuite) TestRetryKeepAlive() {
st := &Session{}
st.retryKeepAlive.Store(true)
sf := &Session{}
sf.retryKeepAlive.Store(false)
cases := []struct {
tag string
input *Session
expect bool
}{
{"not_set", &Session{}, false},
{"set_true", st, true},
{"set_false", sf, false},
}
for _, c := range cases {
s.Run(c.tag, func() {
s.Equal(c.expect, c.input.isRetryingKeepAlive())
})
}
}
func (s *SessionSuite) TestGoingStop() {
ctx := context.Background()
sdisconnect := NewSession(ctx, s.metaRoot, s.client)