Skip to content

Commit

Permalink
tests: don't panic if the fd is closed
Browse files Browse the repository at this point in the history
Despite 1446241 ("tests: make sure the directory handle is kept
alive in rename loop"), we are still getting the same errors. I suspect
the issue is that the directory is getting deleted while we're still in
the loop. To work around this, don't panic if the directory is closed
(which must happen before the Go test infrastructure deletes the
temporary directory).

Fixes:1446241e8a9f ("tests: make sure the directory handle is kept alive in rename loop")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
cyphar committed Sep 30, 2024
1 parent 626b5a5 commit 208ded3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions util_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ func doRenameExchangeLoop(pauseCh chan struct{}, exitCh <-chan struct{}, dir *os
// "correct" state.
for i := 0; i < 2; i++ {
err := unix.Renameat2(int(dir.Fd()), pathA, int(dir.Fd()), pathB, unix.RENAME_EXCHANGE)
if err != nil && !errors.Is(err, unix.EBADF) {
if err != nil && int(dir.Fd()) != -1 && !errors.Is(err, unix.EBADF) {
// Should never happen, and if it does we will potentially
// enter a bad filesystem state if we get paused.
panic(fmt.Sprintf("renameat2([%d]%q, %q, ..., %q, RENAME_EXCHANGE) = %v", int(dir.Fd()), dir.Name(), pathA, pathB, err))
}
// Make sure GC doesn't close the directory handle.
runtime.KeepAlive(dir)
}
}
// Make sure GC doesn't close the directory handle.
runtime.KeepAlive(dir)
}
}

Expand Down

0 comments on commit 208ded3

Please sign in to comment.