fix: Close client before remove worker client (#41253)

issue: #41252

---------

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
cai.zhang 2025-04-15 10:26:31 +08:00 committed by GitHub
parent 3963fc818f
commit bc11feae74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -2356,8 +2356,11 @@ func newTestServer(t *testing.T, opts ...Option) *Server {
svr.SetEtcdClient(etcdCli) svr.SetEtcdClient(etcdCli)
svr.SetTiKVClient(globalTestTikv) svr.SetTiKVClient(globalTestTikv)
dm := mocks.NewMockDataNodeClient(t)
dm.EXPECT().Close().Return(nil).Maybe()
svr.dataNodeCreator = func(ctx context.Context, addr string, nodeID int64) (types.DataNodeClient, error) { svr.dataNodeCreator = func(ctx context.Context, addr string, nodeID int64) (types.DataNodeClient, error) {
return mocks.NewMockDataNodeClient(t), nil return dm, nil
} }
svr.mixCoordCreator = func(ctx context.Context) (types.MixCoord, error) { svr.mixCoordCreator = func(ctx context.Context) (types.MixCoord, error) {
return newMockMixCoord(), nil return newMockMixCoord(), nil

View File

@ -90,7 +90,12 @@ func (nm *IndexNodeManager) RemoveNode(nodeID typeutil.UniqueID) {
log.Ctx(nm.ctx).Debug("remove IndexNode", zap.Int64("nodeID", nodeID)) log.Ctx(nm.ctx).Debug("remove IndexNode", zap.Int64("nodeID", nodeID))
nm.lock.Lock() nm.lock.Lock()
defer nm.lock.Unlock() defer nm.lock.Unlock()
delete(nm.nodeClients, nodeID) if in, ok := nm.nodeClients[nodeID]; ok {
if err := in.Close(); err != nil {
log.Warn("Failed to close client connection", zap.Error(err))
}
delete(nm.nodeClients, nodeID)
}
delete(nm.stoppingNodes, nodeID) delete(nm.stoppingNodes, nodeID)
metrics.IndexNodeNum.WithLabelValues().Set(float64(len(nm.nodeClients))) metrics.IndexNodeNum.WithLabelValues().Set(float64(len(nm.nodeClients)))
} }