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

Protect memroystore connection obejct with a mutex #339

Merged
merged 1 commit into from
Jun 4, 2021
Merged

Conversation

Sriep
Copy link
Contributor

@Sriep Sriep commented Jun 2, 2021

Wrapped the memorystore.connection map in an object and protected get and set methods with a mutex.
Addresses issue #265.

@Sriep Sriep linked an issue Jun 2, 2021 that may be closed by this pull request
@Sriep Sriep changed the title connection add mutex Protect memroystore connection obejct with a mutex Jun 2, 2021
@Sriep Sriep requested a review from bbist June 2, 2021 18:01
@Sriep Sriep added the bug label Jun 2, 2021
@Sriep Sriep requested a review from platsko June 3, 2021 23:35
Copy link
Contributor

@platsko platsko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it is good practice to use a pointer to mutex: https://github.com/uber-go/guide/blob/master/style.md#zero-value-mutexes-are-valid

@Sriep
Copy link
Contributor Author

Sriep commented Jun 4, 2021

The problem is lint raises an objection to copying mutex. Below are the lint errors if I change the mutex to not be a pointer:

core/memorystore/connection.go:120:45: copylocks: call of context.WithValue copies lock value: 0chain.net/core/memorystore.connections contains sync.RWMutex (govet)
		return context.WithValue(ctx, CONNECTION, cMap)
		                                          ^
core/memorystore/connection.go:169:45: copylocks: call of context.WithValue copies lock value: 0chain.net/core/memorystore.connections contains sync.RWMutex (govet)
		return context.WithValue(ctx, CONNECTION, cMap)
		                                          ^
core/memorystore/connection.go:211:10: copylocks: assignment copies lock value to cMap: 0chain.net/core/memorystore.connections contains sync.RWMutex (govet)
	cMap := c.(connections)
	        ^

@Sriep Sriep merged commit 74ada53 into master Jun 4, 2021
@Sriep Sriep deleted the connectinos branch June 4, 2021 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race Issue: Protect package global map connections
2 participants