You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to create a same folder concurrently, one Mkdir should return an error stating the path already exists. MemMapFS works a lot of the time as expected but sometimes the error is not returned.
See below, a test case to reproduce the problem:
import (
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
"testing"
)
func TestMemMap(t *testing.T) {
for i := 0; i < 100; i++ {
fs := afero.NewMemMapFs()
dir := "testDir"
c1 := make(chan error)
c2 := make(chan error)
go func() {
c1 <- fs.Mkdir(dir, 0755)
}()
go func() {
c2 <- fs.Mkdir(dir, 0755)
}()
// Only one attempt of creating the directory should succeed.
err1 := <-c1
err2 := <-c2
require.NotEqual(t, err1, err2, "run #%v", i)
}
}
The failure can happen at any time
e.g.
=== RUN TestMemMap
TestMemMap: test_test.go:27:
Error Trace: test_test.go:27
Error: Should not be: <nil>
Test: TestMemMap
Messages: run #17
--- FAIL: TestMemMap (0.00s)
The text was updated successfully, but these errors were encountered:
* The backing map is protected by a RWMutex
* This commit double checks for the existence of the directory inside the write lock to avoid potential data races when multiple goroutines tries to create
the same directory.
Fixesspf13#361Fixesspf13#298
bep
added a commit
to bep/afero
that referenced
this issue
Nov 14, 2022
* The backing map is protected by a RWMutex
* This commit double checks for the existence of the directory inside the write lock to avoid potential data races when multiple goroutines tries to create
the same directory.
Fixesspf13#361Fixesspf13#298
bep
added a commit
to bep/afero
that referenced
this issue
Nov 14, 2022
* The backing map is protected by a RWMutex
* This commit double checks for the existence of the directory inside the write lock to avoid potential data races when multiple goroutines tries to create
the same directory.
Fixesspf13#361Fixesspf13#298
When trying to create a same folder concurrently, one Mkdir should return an error stating the path already exists. MemMapFS works a lot of the time as expected but sometimes the error is not returned.
See below, a test case to reproduce the problem:
The failure can happen at any time
e.g.
The text was updated successfully, but these errors were encountered: