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

Lock EnumCodec.membersMap during reads and writes #2088

Closed

Conversation

jamesroutley
Copy link

We've been seeing a nondeterministic fatal error: concurrent map writes error while using PGX. I traced it to the c.membersMap[s] = s line, and I think that this is a true issue - there doesn't appear to be anything preventing concurrent access to this map.

This PR adds a sync.RWMutex to EnumCodec and calls the appropriate RLock or Lock methods around read or write access.

We've been seeing a nondeterministic `fatal error: concurrent map
writes` error while using PGX. I traced it to the `c.membersMap[s] = s`
line, and I think that this is a true issue - there doesn't appear to be
anything preventing concurrent access to this map.

This PR adds a `sync.RWMutex` to `EnumCodec` and calls the appropriate
`RLock` or `Lock` methods around read or write access.
}

func (EnumCodec) FormatSupported(format int16) bool {
func (*EnumCodec) FormatSupported(format int16) bool {
Copy link
Author

Choose a reason for hiding this comment

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

I needed to make these pointer receivers to avoid FormatSupported passes lock by value: github.com/jackc/pgx/v5/pgtype.EnumCodec contains sync.RWMutex go vet errors

@jamesroutley jamesroutley deleted the lock-enum-codec-members-map branch November 7, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant