From bd8d9d628e185d75e3a6b3bff6945644f0c2660c Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Wed, 13 Sep 2023 18:14:10 +0800 Subject: [PATCH 1/2] ttl: fix potential go leak for ttl in test --- domain/domain.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index ee0d6774655bf..47c0e1b08ebe7 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -995,6 +995,7 @@ func (do *Domain) Close() { } ttlJobManager := do.ttlJobManager.Load() if ttlJobManager != nil { + logutil.BgLogger().Info("stop ttlJobManager") ttlJobManager.Stop() err := ttlJobManager.WaitStopped(context.Background(), func() time.Duration { if intest.InTest { @@ -1004,6 +1005,8 @@ func (do *Domain) Close() { }()) if err != nil { logutil.BgLogger().Warn("fail to wait until the ttl job manager stop", zap.Error(err)) + } else { + logutil.BgLogger().Info("ttlJobManager exited.") } } do.releaseServerID(context.Background()) @@ -2915,17 +2918,9 @@ func (do *Domain) serverIDKeeper() { // StartTTLJobManager creates and starts the ttl job manager func (do *Domain) StartTTLJobManager() { - do.wg.Run(func() { - defer func() { - logutil.BgLogger().Info("ttlJobManager exited.") - }() - - ttlJobManager := ttlworker.NewJobManager(do.ddl.GetID(), do.sysSessionPool, do.store, do.etcdClient, do.ddl.OwnerManager().IsOwner) - do.ttlJobManager.Store(ttlJobManager) - ttlJobManager.Start() - - <-do.exit - }, "ttlJobManager") + ttlJobManager := ttlworker.NewJobManager(do.ddl.GetID(), do.sysSessionPool, do.store, do.etcdClient, do.ddl.OwnerManager().IsOwner) + do.ttlJobManager.Store(ttlJobManager) + ttlJobManager.Start() } // TTLJobManager returns the ttl job manager on this domain From 665763a49cec2f0c0b45857f3b619c7f08c13cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= Date: Wed, 13 Sep 2023 18:23:58 +0800 Subject: [PATCH 2/2] Update domain/domain.go Co-authored-by: Weizhen Wang --- domain/domain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain/domain.go b/domain/domain.go index 47c0e1b08ebe7..4890eb67b74b8 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -995,7 +995,7 @@ func (do *Domain) Close() { } ttlJobManager := do.ttlJobManager.Load() if ttlJobManager != nil { - logutil.BgLogger().Info("stop ttlJobManager") + logutil.BgLogger().Info("stopping ttlJobManager") ttlJobManager.Stop() err := ttlJobManager.WaitStopped(context.Background(), func() time.Duration { if intest.InTest {