golang/go · error

VirtualQuery %s: %w

Error message

VirtualQuery %s: %w

What it means

Windows mmap helper: `windows.VirtualQuery` failed when querying the `MemoryBasicInformation` for the mapped region. This is an uncommon, kernel-level failure that indicates the mapping handle/address is not in a queryable state — usually a symptom of OS-level memory or handle corruption rather than a user config issue.

Source

Thrown at src/cmd/go/internal/mmap/mmap_windows.go:37

		return Data{}, err
	}
	size := st.Size()
	if size == 0 {
		return Data{f, nil}, nil
	}
	h, err := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, 0, 0, nil)
	if err != nil {
		return Data{}, fmt.Errorf("CreateFileMapping %s: %w", f.Name(), err)
	}

	addr, err := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, 0)
	if err != nil {
		return Data{}, fmt.Errorf("MapViewOfFile %s: %w", f.Name(), err)
	}
	var info windows.MemoryBasicInformation
	err = windows.VirtualQuery(addr, &info, unsafe.Sizeof(info))
	if err != nil {
		return Data{}, fmt.Errorf("VirtualQuery %s: %w", f.Name(), err)
	}
	data := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.RegionSize))
	if len(data) < int(size) {
		// In some cases, especially on 386, we may not receive a in incomplete mapping:
		// one that is shorter than the file itself. Return an error in those cases because
		// incomplete mappings are not useful.
		return Data{}, fmt.Errorf("mmapFile: received incomplete mapping of file")
	}
	return Data{f, data[:int(size)]}, nil
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Restart the machine / process to clear transient state.
  2. Update Windows and the Go toolchain to rule out a known kernel/tooling bug.
  3. Clear the cache (`go clean -modcache`) and retry.
Defensive patterns

Strategy: retry

Try / catch

// VirtualQuery failures are usually transient OS state; retry once.
for i := 0; i < 2; i++ {
    if err := runGoCmd(); err == nil || !isVirtualQueryErr(err) { return err }
    time.Sleep(2 * time.Second)
}

Prevention

When it happens

Trigger: The mapping address is invalid; system-level memory corruption; rare Windows kernel/VM issue; extremely low-resource conditions.

Common situations: Very rare in practice; usually surfaces alongside OS instability, virtualization bugs, or low memory.

Related errors


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