]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/clean: add logging to help debug openbsd flakes
authorMichael Matloob <matloob@golang.org>
Tue, 18 Mar 2025 17:00:42 +0000 (13:00 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 18 Mar 2025 18:22:30 +0000 (11:22 -0700)
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 <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Matloob <matloob@golang.org>

src/cmd/go/internal/clean/clean.go

index 37566025cebd8ada4db89b32a51bf15f7259be66..18c5ae23fcd814a32989a1c78b88c4d81ce86a19 100644 (file)
@@ -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("<err: %s>", 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.