2 Commits
Author SHA1 Message Date
clawbot 5779f4efcd Go on past cache entries the reconciliation pass cannot read (closes #343)
check / check (push) Canceled after 0s
The walk of each storage directory returned the error of an entry it
could not read. The pass then stopped before its later checks, and the
same entry stopped every later pass. Now reconcileFiles skips a
directory it cannot list and a file whose info it cannot read. It logs
a warning naming the path and the error, and the walk goes on. It reads
each file's info itself and hands it to reconcileVariantFile and
reconcileSourceFile. A cancelled context still stops the walk with its
error. README.md says so under Storage.

Model: opus-5-5
2026-10-27 00:16:54 +00:00
clawbot b7a0d35732 Test that reconciliation goes on past entries it cannot read
check / check (push) Canceled after 0s
Each storage directory gets a directory the pass cannot list and a file
whose info it cannot read. Their paths are longer than Linux accepts, so
even root fails to read them. The walk reaches them before the cache's
files. The test wants a warning naming each path and the error. It also
wants the rest of the pass done: a variant file with no row adopted, the
row of a missing variant file dropped, a source file with no row
removed, and a wrong usage total corrected. On next the pass stops at
the first such directory and returns its error. The fix follows in the
next commit.

Model: opus-5-5
2026-10-27 00:14:45 +00:00
3 changed files with 33 additions and 85 deletions

No files matched your search

+2 -3
View File
@@ -35,9 +35,8 @@ P2: security: per-origin rate limiting
so one such entry stopped every pass before its later checks.
- Each skipped entry gets the warning "skipped unreadable entry in cache
directory", with its path and the error.
- `reconcileFiles` reads each file's info once, before the temp-file check,
and hands it to `sweepStaleTempFile`, `reconcileVariantFile` or
`reconcileSourceFile`.
- `reconcileFiles` reads each file's info and hands it to
`reconcileVariantFile` and `reconcileSourceFile`.
- A cancelled context still stops the walk with its error.
- 2026-10-26 the reconciliation pass drops a variant's accounting row only when
its file is missing (closes #340). Any other error reading the file's size
+15 -10
View File
@@ -542,18 +542,18 @@ func (c *Cache) reconcileFiles(
return nil
}
info, err := entry.Info()
if err != nil {
c.log.Warn("skipped unreadable entry in cache directory",
"path", path, "error", err)
name := entry.Name()
if strings.HasPrefix(name, tempFilePrefix) {
c.sweepStaleTempFile(path, entry)
return nil
}
name := entry.Name()
if strings.HasPrefix(name, tempFilePrefix) {
c.sweepStaleTempFile(path, info)
info, err := entry.Info()
if err != nil {
c.log.Warn("skipped unreadable entry in cache directory",
"path", path, "error", err)
return nil
}
@@ -907,12 +907,17 @@ func (c *Cache) correctUsageTotal(
// sweepStaleTempFile removes a temp file left behind by a crashed
// write once it is old enough that no in-flight store can own it.
func (c *Cache) sweepStaleTempFile(path string, info fs.FileInfo) {
func (c *Cache) sweepStaleTempFile(path string, entry fs.DirEntry) {
info, err := entry.Info()
if err != nil {
return
}
if time.Since(info.ModTime()) < staleTempFileAge {
return
}
err := os.Remove(path)
err = os.Remove(path)
if err != nil && !os.IsNotExist(err) {
c.log.Warn("failed to remove stale temp file", "path", path, "error", err)
+16 -72
View File
@@ -787,14 +787,15 @@ func TestReconcileVariantRowsDropsOnlyRowsOfMissingFiles(t *testing.T) {
}
}
// openDirectoryNearPathLimit makes a chain of directories inside dir, each
// makeEntriesTooLongToRead makes a chain of directories inside dir, each
// named with 255 zeros, the longest name Linux allows. Linux refuses a path
// of 4096 bytes or more, and the chain goes as deep as it can below that.
// It returns the chain's deepest directory as an os.Root, closed when the
// test ends. An entry made through it with a 255-byte name has a path even
// the root user cannot read. The os.Root can make that entry because it
// names the entry only by its name, not by the whole path.
func openDirectoryNearPathLimit(t *testing.T, dir string) *os.Root {
// In its deepest directory it makes a directory and a file whose paths
// reach that length. Even root can then neither list that directory nor
// read the file's info. It returns their two paths. It makes them through
// an os.Root, which names one directory at a time, as no call may name
// the whole path.
func makeEntriesTooLongToRead(t *testing.T, dir string) []string {
t.Helper()
name := strings.Repeat("0", 255)
@@ -804,64 +805,32 @@ func openDirectoryNearPathLimit(t *testing.T, dir string) *os.Root {
deepest = filepath.Join(deepest, name)
}
err := os.MkdirAll(deepest, StorageDirPerm)
chain, err := filepath.Rel(dir, deepest)
if err != nil {
t.Fatalf("failed to make a chain of directories: %v", err)
t.Fatalf("filepath.Rel() error = %v", err)
}
root, err := os.OpenRoot(deepest)
root, err := os.OpenRoot(dir)
if err != nil {
t.Fatalf("os.OpenRoot(%s) error = %v", deepest, err)
t.Fatalf("os.OpenRoot(%s) error = %v", dir, err)
}
t.Cleanup(func() { _ = root.Close() })
defer func() { _ = root.Close() }()
return root
}
// makeEntriesTooLongToRead makes a directory and a file in the directory
// that openDirectoryNearPathLimit opens inside dir. Even the root user can
// then neither list that directory nor read the file's info. It returns
// their two paths.
func makeEntriesTooLongToRead(t *testing.T, dir string) []string {
t.Helper()
deepest := openDirectoryNearPathLimit(t, dir)
dirName := strings.Repeat("0", 255)
err := deepest.Mkdir(dirName, StorageDirPerm)
err = root.MkdirAll(filepath.Join(chain, name), StorageDirPerm)
if err != nil {
t.Fatalf("failed to make a directory too deep to list: %v", err)
}
fileName := strings.Repeat("1", 255)
err = deepest.WriteFile(fileName, []byte("unreadable"), StorageFilePerm)
err = root.WriteFile(filepath.Join(chain, fileName), []byte("unreadable"),
StorageFilePerm)
if err != nil {
t.Fatalf("failed to make a file too deep to read: %v", err)
}
return []string{
filepath.Join(deepest.Name(), dirName),
filepath.Join(deepest.Name(), fileName),
}
}
// makeTempFileTooLongToRead makes a temp file in the directory that
// openDirectoryNearPathLimit opens inside dir. Even the root user then
// cannot read its info. It returns its path.
func makeTempFileTooLongToRead(t *testing.T, dir string) string {
t.Helper()
deepest := openDirectoryNearPathLimit(t, dir)
name := tempFilePrefix + strings.Repeat("1", 255-len(tempFilePrefix))
err := deepest.WriteFile(name, []byte("partial"), StorageFilePerm)
if err != nil {
t.Fatalf("failed to make a temp file too deep to read: %v", err)
}
return filepath.Join(deepest.Name(), name)
return []string{filepath.Join(deepest, name), filepath.Join(deepest, fileName)}
}
// TestReconciliationGoesOnPastEntriesItCannotRead puts, in each storage
@@ -948,31 +917,6 @@ func TestReconciliationGoesOnPastEntriesItCannotRead(t *testing.T) {
}
}
// TestReconciliationWarnsOfTempFilesItCannotRead puts, in each storage
// directory, a temp file whose info the pass cannot read. The pass must
// log a warning naming each one's path and the error, as it does for any
// other file whose info it cannot read.
func TestReconciliationWarnsOfTempFilesItCannotRead(t *testing.T) {
t.Parallel()
cache, _ := newEvictionTestCache(t, 1<<30)
unreadable := []string{
makeTempFileTooLongToRead(t, cache.variants.baseDir),
makeTempFileTooLongToRead(t, cache.srcContent.baseDir),
}
logs := reconcileAsAtStartup(t, cache)
for _, path := range unreadable {
assertWarningNames(t, logs, path)
if !strings.Contains(logs, path+": "+syscall.ENAMETOOLONG.Error()) {
t.Errorf("no log line gives the error reading %s", path)
}
}
}
// TestPeriodicReconciliationAdoptsFileThatAppearsAfterStartup proves
// reconciliation is not a one-shot startup-only pass: it must also run
// on the periodic ticker, so a variant file that lands on disk with no