Fix retryKeepAlive assertion panic (#25005)

Signed-off-by: wayblink <anyang.wang@zilliz.com>
This commit is contained in:
wayblink 2023-06-20 14:16:46 +08:00 committed by GitHub
parent 95282e80c0
commit 1b2f6d3443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -772,7 +772,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
}
@ -851,6 +851,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

@ -803,6 +803,29 @@ func (s *SessionSuite) TestGoingStop() {
}
}
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) TestRevoke() {
ctx := context.Background()
disconnected := NewSession(ctx, s.metaRoot, s.client)