Skip to content

Commit 6b18311

Browse files
matloobgopherbot
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Matloob <[email protected]>
1 parent a17c092 commit 6b18311

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

+34
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ package clean
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"io"
13+
"io/fs"
1214
"os"
1315
"path/filepath"
1416
"runtime"
@@ -216,6 +218,15 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
216218
if !cfg.BuildN {
217219
if err := modfetch.RemoveAll(cfg.GOMODCACHE); err != nil {
218220
base.Error(err)
221+
222+
// Add extra logging for the purposes of debugging #68087.
223+
// We're getting ENOTEMPTY errors on openbsd from RemoveAll.
224+
// Check for os.ErrExist, which can match syscall.ENOTEMPTY
225+
// and syscall.EEXIST, because syscall.ENOTEMPTY is not defined
226+
// on all platforms.
227+
if runtime.GOOS == "openbsd" && errors.Is(err, fs.ErrExist) {
228+
logFilesInGOMODCACHE()
229+
}
219230
}
220231
}
221232
}
@@ -228,6 +239,29 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
228239
}
229240
}
230241

242+
// logFilesInGOMODCACHE reports the file names and modes for the files in GOMODCACHE using base.Error.
243+
func logFilesInGOMODCACHE() {
244+
var found []string
245+
werr := filepath.WalkDir(cfg.GOMODCACHE, func(path string, d fs.DirEntry, err error) error {
246+
if err != nil {
247+
return err
248+
}
249+
var mode string
250+
info, err := d.Info()
251+
if err == nil {
252+
mode = info.Mode().String()
253+
} else {
254+
mode = fmt.Sprintf("<err: %s>", info.Mode())
255+
}
256+
found = append(found, fmt.Sprintf("%s (mode: %s)", path, mode))
257+
return nil
258+
})
259+
if werr != nil {
260+
base.Errorf("walking files in GOMODCACHE (for debugging go.dev/issue/68087): %v", werr)
261+
}
262+
base.Errorf("files in GOMODCACHE (for debugging go.dev/issue/68087):\n%s", strings.Join(found, "\n"))
263+
}
264+
231265
var cleaned = map[*load.Package]bool{}
232266

233267
// TODO: These are dregs left by Makefile-based builds.

0 commit comments

Comments
 (0)