Skip to content

Commit

Permalink
fix wg.Wait() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yhy0 committed Apr 15, 2024
1 parent 9de06eb commit 3fc391e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/task/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() // 现在可以安全地等待,而不会持有锁
}

0 comments on commit 3fc391e

Please sign in to comment.