From 6b18311bbc94864af48d10aad73fd4eb7ea0d9a1 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 18 Mar 2025 13:00:42 -0400 Subject: [PATCH] cmd/go/internal/clean: add logging to help debug openbsd flakes This change adds extra logging in the case where there's an error removing all the files in the gomodcache using modfetch.RemoveAll. It logs the names of the files found in GOMODCACHE as well as their modes. The modes are included because they should all be writable by the time we call robustio.RemoveAll. For #68087 Change-Id: Id9ae68bf6a3392baf88ec002d08fed1faf525927 Reviewed-on: https://go-review.googlesource.com/c/go/+/658816 Reviewed-by: Alan Donovan LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Matloob --- src/cmd/go/internal/clean/clean.go | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/cmd/go/internal/clean/clean.go b/src/cmd/go/internal/clean/clean.go index 37566025ce..18c5ae23fc 100644 --- a/src/cmd/go/internal/clean/clean.go +++ b/src/cmd/go/internal/clean/clean.go @@ -7,8 +7,10 @@ package clean import ( "context" + "errors" "fmt" "io" + "io/fs" "os" "path/filepath" "runtime" @@ -216,6 +218,15 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) { if !cfg.BuildN { if err := modfetch.RemoveAll(cfg.GOMODCACHE); err != nil { base.Error(err) + + // Add extra logging for the purposes of debugging #68087. + // We're getting ENOTEMPTY errors on openbsd from RemoveAll. + // Check for os.ErrExist, which can match syscall.ENOTEMPTY + // and syscall.EEXIST, because syscall.ENOTEMPTY is not defined + // on all platforms. + if runtime.GOOS == "openbsd" && errors.Is(err, fs.ErrExist) { + logFilesInGOMODCACHE() + } } } } @@ -228,6 +239,29 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) { } } +// logFilesInGOMODCACHE reports the file names and modes for the files in GOMODCACHE using base.Error. +func logFilesInGOMODCACHE() { + var found []string + werr := filepath.WalkDir(cfg.GOMODCACHE, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + var mode string + info, err := d.Info() + if err == nil { + mode = info.Mode().String() + } else { + mode = fmt.Sprintf("", info.Mode()) + } + found = append(found, fmt.Sprintf("%s (mode: %s)", path, mode)) + return nil + }) + if werr != nil { + base.Errorf("walking files in GOMODCACHE (for debugging go.dev/issue/68087): %v", werr) + } + base.Errorf("files in GOMODCACHE (for debugging go.dev/issue/68087):\n%s", strings.Join(found, "\n")) +} + var cleaned = map[*load.Package]bool{} // TODO: These are dregs left by Makefile-based builds. -- 2.51.0