From 3fc391e0d6aea3cdcf9c8950f08209b6f07b2adb Mon Sep 17 00:00:00 2001 From: yhy0 <31311038+yhy0@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:41:08 +0800 Subject: [PATCH] fix wg.Wait() bug --- pkg/task/scan.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/task/scan.go b/pkg/task/scan.go index 69101c5..e48fbe4 100644 --- a/pkg/task/scan.go +++ b/pkg/task/scan.go @@ -139,7 +139,8 @@ func (t *Task) DoneWg(host string) { func (t *Task) WaitWg(host string) { t.WgLock.Lock() // 保护对ScanTask映射的访问 - defer t.WgLock.Unlock() + wg := t.ScanTask[host].Wg + t.WgLock.Unlock() // 解锁,以便其他goroutine可以操作WaitGroup - t.ScanTask[host].Wg.Wait() + wg.Wait() // 现在可以安全地等待,而不会持有锁 }