Skip to content

Commit

Permalink
fix: concurrent map iteration and map write
Browse files Browse the repository at this point in the history
Signed-off-by: Cookie Wang <[email protected]>
  • Loading branch information
luckymrwang committed Jul 12, 2023
1 parent 0610339 commit 90b93d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This changelog keeps track of work items that have been completed and are ready

- **Scaler**: remplement custom interceptor metrics ([#718](https://github.com/kedacore/http-add-on/issues/718))
- **Operator**: Remove ScaledObject `name` & `app` custom labels ([#717](https://github.com/kedacore/http-add-on/issues/717))
- **Interceptor**: fatal error: concurrent map iteration and map write ([#726](https://github.com/kedacore/http-add-on/issues/726))

### Deprecations

Expand Down
4 changes: 3 additions & 1 deletion pkg/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (r *Memory) Current() (*Counts, error) {
r.mut.RLock()
defer r.mut.RUnlock()
cts := NewCounts()
cts.Counts = r.countMap
for key, val := range r.countMap {
cts.Counts[key] = val
}
return cts, nil
}
23 changes: 23 additions & 0 deletions pkg/queue/queue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package queue

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCurrent(t *testing.T) {
r := require.New(t)
memory := NewMemory()
err := memory.Resize("host1", 1)
r.NoError(err)
current, err := memory.Current()
r.NoError(err)
r.Equal(current.Counts, memory.countMap)

err = memory.Resize("host1", 1)
r.NoError(err)
err = memory.Resize("host2", 1)
r.NoError(err)
r.NotEqual(current.Counts, memory.countMap)
}

0 comments on commit 90b93d0

Please sign in to comment.