From 208ded324d88817d11802fc83579508f7e1950fb Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Mon, 30 Sep 2024 14:15:41 +0200 Subject: [PATCH] tests: don't panic if the fd is closed Despite 1446241e8a9f ("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 --- util_linux_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util_linux_test.go b/util_linux_test.go index 7b45933..85635b8 100644 --- a/util_linux_test.go +++ b/util_linux_test.go @@ -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) } }