Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: SidecarEgressMap.Get() throws concurrent map access error intermittently #219

Closed
shriramsharma opened this issue May 20, 2022 · 0 comments · Fixed by #220
Closed
Labels
bug Something isn't working

Comments

@shriramsharma
Copy link
Collaborator

Describe the bug
SidecarEgressMap.Get() throws concurrent map access error intermittently.
The map access inside the func is not thread-safe.

func (s *SidecarEgressMap) Get(key string) map[string]SidecarEgress {

Steps To Reproduce
This error is pretty intermittent. I wrote a test to reproduce this error.

func TestSidecarEgressGet(t *testing.T) {

	egressMap := NewSidecarEgressMap()
	egressMap.Put("pkey1", "pkey2", "fqdn", map[string]string{"pkey2": "pkey2"})

	ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
	defer cancel()

	go func(ctx context.Context) {
		for {
			select {
			case <-ctx.Done():
				return
			default:
				egressMap.Put("pkey1", string(uuid.NewUUID()), "fqdn", map[string]string{"pkey2": "pkey2"})
			}
		}
	}(ctx)

	for {
		select {
		case <-ctx.Done():
			return
		default:
			assert.NotNil(t, egressMap.Get("pkey1"))
		}
	}

}

Error:

fatal error: concurrent map read and map write

goroutine 10 [running]:
runtime.throw({0x181ef9c, 0xc000495980})
	/Users/ssharma34/shriram/sandbox/goroots/go1.17/src/runtime/panic.go:1198 +0x71 fp=0xc000083e70 sp=0xc000083e40 pc=0x1036df1
runtime.mapaccess1_faststr(0xc0001127e0, 0xc000203a00, {0x180b471, 0x5})
	/Users/ssharma34/shriram/sandbox/goroots/go1.17/src/runtime/map_faststr.go:21 +0x3a5 fp=0xc000083ed8 sp=0xc000083e70 pc=0x1014045
github.com/istio-ecosystem/admiral/admiral/pkg/controller/common.(*SidecarEgressMap).Get(...)
	/Users/ssharma34/shriram/personal/github/admiral/admiral/pkg/controller/common/types.go:180

Expected behavior
Have a mutex around the map for synchronized access.

@shriramsharma shriramsharma added the bug Something isn't working label May 20, 2022
shriramsharma added a commit to shriramsharma/admiral that referenced this issue May 20, 2022
Added mutex to sync access to the SidecarEgressMap
shriramsharma added a commit to shriramsharma/admiral that referenced this issue May 24, 2022
Added mutex to sync access to the SidecarEgressMap

Signed-off-by: Shriram Sharma <shriram_sharma@intuit.com>
shriramsharma added a commit to shriramsharma/admiral that referenced this issue May 25, 2022
Added mutex to sync access to the SidecarEgressMap

Signed-off-by: Shriram Sharma <shriram_sharma@intuit.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant