golang/go · error

updating go.sum: %w

Error message

updating go.sum: %w

What it means

Wraps a failure from lockedfile.Transform while rewriting go.sum during TidyGoSum (and friends). Transform applies a function to the file content atomically under the side lock; any underlying error — disk full, permission denied, lockedfile conflict, fsync failure — is wrapped as 'updating go.sum: %w'.

Source

Thrown at src/cmd/go/internal/modfetch/fetch.go:968

	if readonly {
		return ErrGoSumDirty
	}
	if fsys.Replaced(f.goSumFile) {
		base.Fatalf("go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay")
	}

	// Make a best-effort attempt to acquire the side lock, only to exclude
	// previous versions of the 'go' command from making simultaneous edits.
	if unlock, err := SideLock(ctx); err == nil {
		defer unlock()
	}

	err := lockedfile.Transform(f.goSumFile, func(data []byte) ([]byte, error) {
		tidyGoSum := tidyGoSum(f, data, keep)
		return tidyGoSum, nil
	})
	if err != nil {
		return fmt.Errorf("updating go.sum: %w", err)
	}

	f.sumState.status = make(map[modSum]modSumStatus)
	f.sumState.overwrite = false
	return nil
}

// TidyGoSum returns a tidy version of the go.sum file.
// A missing go.sum file is treated as if empty.
func (f *Fetcher) TidyGoSum(keep map[module.Version]bool) (before, after []byte) {
	f.mu.Lock()
	defer f.mu.Unlock()
	before, err := lockedfile.Read(f.goSumFile)
	if err != nil && !errors.Is(err, fs.ErrNotExist) {
		base.Fatalf("reading go.sum: %v", err)
	}
	after = tidyGoSum(f, before, keep)
	return before, after

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Check filesystem permissions on the module root and ensure the go.sum file is writable.
  2. Free disk space; inodes as well as bytes.
  3. Avoid running multiple go commands against one module dir concurrently, or ensure GOMODCACHE on a local filesystem.
  4. If on NFS/network FS, move GOMODCACHE to a local path.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight check that go.sum is writable and the volume has space.
func goSumWritable(p string) error {
    fi, err := os.Stat(p)
    if os.IsNotExist(err) { return nil }
    if err != nil { return err }
    if fi.Mode()&0200 == 0 { return fmt.Errorf("go.sum not writable") }
    return nil
}

Try / catch

err := f.TidyGoSum(keep)
if err != nil {
    if errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrNoSpace) {
        // surface to operator; these are environmental
    }
    return fmt.Errorf("cannot update go.sum: %w", err)
}

Prevention

When it happens

Trigger: lockedfile.Transform returns err != nil on the go.sum file. Happens during go mod tidy / go get that rewrites go.sum under the SideLock.

Common situations: Read-only workspace (CI sandbox), full disk, NFS share with broken locking, GOMODCACHE on a volume without fsync, concurrent go commands racing on the same module dir without the side lock.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/8d791524290df8a6. Report an issue: GitHub.