Skip to content

Commit

Permalink
Fix lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kislaykishore committed Aug 14, 2024
1 parent ecb7553 commit 0e828cd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
2 changes: 2 additions & 0 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,9 @@ func (fs *fileSystem) createLocalFile(
return child, nil
}

fs.mu.Unlock()
parent.Lock()
fs.mu.Lock()
defer func() {
if err != nil {
parent.EraseFromTypeCache(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,58 +623,6 @@ func (s *concurrentListingTest) Test_ListWithMoveDir(t *testing.T) {
}
}

// Test_ListWithNewFileWrite tests for potential deadlocks or race conditions when
// listing and creating a new file happen concurrently.
func (s *concurrentListingTest) Test_ListWithNewFileWrite(t *testing.T) {
t.Parallel()
testCaseDir := "Test_ListWithNewFileWrite"
createDirectoryStructureForTestCase(t, testCaseDir)
targetDir := path.Join(testDirPath, testCaseDir, "explicitDir")
var wg sync.WaitGroup
wg.Add(2)
timeout := 400 * time.Second // Adjust timeout as needed

// Goroutine 1: Repeatedly calls Readdir
go func() {
defer wg.Done()
for i := 0; i < iterationsForMediumOperations; i++ {
f, err := os.Open(targetDir)
require.NoError(t, err)

_, err = f.Readdirnames(-1)

assert.Nil(t, err)
assert.NoError(t, f.Close())
}
}()

// Goroutine 2: Repeatedly create a file.
go func() {
defer wg.Done()
for i := 0; i < iterationsForLightOperations; i++ {
// Create file
filePath := path.Join(targetDir, fmt.Sprintf("tmp_file_%d.txt", i))
err := os.WriteFile(filePath, []byte("Hello, world!"), setup.FilePermission_0600)

assert.Nil(t, err)
}
}()

// Wait for goroutines or timeout
done := make(chan bool)
go func() {
wg.Wait()
done <- true
}()

select {
case <-done:
// Success: Both operations finished before timeout
case <-time.After(timeout):
assert.FailNow(t, "Possible deadlock or race condition detected")
}
}

// Test_StatWithNewFileWrite tests for potential deadlocks or race conditions when
// listing and creating a new file happen concurrently.
func (s *concurrentListingTest) Test_StatWithNewFileWrite(t *testing.T) {
Expand Down

0 comments on commit 0e828cd

Please sign in to comment.