Skip to content

Commit

Permalink
fix: race condition when updating snapshots in parallel (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Apr 5, 2024
1 parent 9822328 commit e31ee30
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snaps/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var (
testsRegistry = newRegistry()
_m = sync.Mutex{}
_m = sync.RWMutex{}
endSequenceByteSlice = []byte(endSequence)
)

Expand Down Expand Up @@ -129,6 +129,9 @@ func newRegistry() *syncRegistry {
//
// If not found returns errSnapNotFound error.
func getPrevSnapshot(testID, snapPath string) (string, int, error) {
_m.RLock()
defer _m.RUnlock()

f, err := os.ReadFile(snapPath)
if err != nil {
return "", -1, errSnapNotFound
Expand Down

0 comments on commit e31ee30

Please sign in to comment.