jackc / pgx

PostgreSQL driver and toolkit for Go
MIT License
10.86k stars 845 forks source link

Lock EnumCodec.membersMap during reads and writes #2088

Closed jamesroutley closed 2 weeks ago

jamesroutley commented 4 months ago

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.