Skip to content

Commit

Permalink
tests: make sure the directory handle is kept alive in rename loop
Browse files Browse the repository at this point in the history
It turns out the GC can close the directory during our loop in CI
sometimes, leading to the following failures (note that dir.Fd() returns
-1, which is a closed directory):

  === RUN   TestPartialLookup_RacingRename/openat2=true/swap-dir-danglinglink-basic
  panic: renameat2([-1]"/tmp/TestPartialLookup_RacingRenameopenat2=trueswap-dir-file-basic3291115487/001/tree", "a/b", ..., "file", RENAME_EXCHANGE) = no such file or directory

  goroutine 552 [running]:
  github.com/cyphar/filepath-securejoin.doRenameExchangeLoop(0xc000027680, 0xc0000276e0, 0xc0000025a8, {0x66c786, 0x3}, {0x66c8f4, 0x4})
      /home/runner/work/filepath-securejoin/filepath-securejoin/util_linux_test.go:111 +0x38c
  created by github.com/cyphar/filepath-securejoin.TestPartialLookup_RacingRename.func1.1 in goroutine 551
      /home/runner/work/filepath-securejoin/filepath-securejoin/lookup_linux_test.go:561 +0x525
  exit status 2

Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Sep 30, 2024
1 parent 37bfb4b commit 1446241
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -111,6 +112,8 @@ func doRenameExchangeLoop(pauseCh chan struct{}, exitCh <-chan struct{}, dir *os
// 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)
}
}
}
Expand Down

0 comments on commit 1446241

Please sign in to comment.