Skip to content

Commit

Permalink
Fix: read/write map is not thread safe (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho authored Nov 28, 2021
1 parent 8b202af commit f0712f8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/zombie/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type Checker struct {
isMockManaged map[string]bool
mux sync.Mutex
mux sync.RWMutex
}

func NewChecker() *Checker {
Expand All @@ -38,7 +38,9 @@ func (c *Checker) Check() []string {
return zombieList
}
func (c *Checker) Search(key string) bool {
c.mux.RLock()
_, ok := c.isMockManaged[key]
c.mux.RUnlock()
if ok {
c.mux.Lock()
c.isMockManaged[key] = true
Expand All @@ -62,7 +64,7 @@ func (c *Checker) FindMocks(ctx context.Context) error {
}

func (c *Checker) setHash(ctx context.Context, trees []string) error {
eg, _ := errgroup.WithContext(ctx)
eg, _ := errgroup.WithContext(ctx)
sem := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0)))

for _, path := range trees {
Expand Down

0 comments on commit f0712f8

Please sign in to comment.