Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #62 from sanposhiho/panic-bug
Browse files Browse the repository at this point in the history
fix: make reservedResourceAmounts fully goroutine-safe
  • Loading branch information
shioshiota authored Sep 27, 2023
2 parents 397216b + f6bad74 commit 0d70d5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/controllers/reserved_resource_amounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ func (c *reservedResourceAmounts) reservedResourceAmount(nn types.NamespacedName
defer func() {
_ = c.keyMutex.UnlockKey(nn.String())
}()

c.RLock()
podResourceAmountMap, ok := c.cache[nn]
c.RUnlock()
if !ok {
return schedulev1alpha1.ResourceAmount{}, sets.New[string]()
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/reserved_resource_amounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,20 @@ var _ = Describe("ReservedResourceAmounts", func() {
remove.Done()
}(i)
}

reservedResourceAmount := &sync.WaitGroup{}
reservedResourceAmount.Add(n)
for i := 0; i < n; i++ {
go func(j int) {
r.reservedResourceAmount(
types.NamespacedName{Name: "test"},
)
reservedResourceAmount.Done()
}(i)
}
add.Wait()
remove.Wait()
reservedResourceAmount.Wait()
})
It("should be threadsafe on specific throttle's namespacedname", func() {
r := newReservedResourceAmounts(1024)
Expand Down

0 comments on commit 0d70d5f

Please sign in to comment.