golang/go · error
CreateFileMapping %s: %w
Error message
CreateFileMapping %s: %w
What it means
Windows mmap helper: `syscall.CreateFileMapping` failed when creating the backing mapping object. The wrapped error is the Windows syscall result — common causes are sharing violations (file open/locked elsewhere), insufficient memory, or path/access issues.
Source
Thrown at src/cmd/go/internal/mmap/mmap_windows.go:27
"os"
"syscall"
"unsafe"
"internal/syscall/windows"
)
func mmapFile(f *os.File) (Data, error) {
st, err := f.Stat()
if err != nil {
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")
}View on GitHub (pinned to b6b368adc5)
Solutions
- Close other processes that may hold the file (other `go` invocations, editors, AV).
- Run `go clean -modcache` to remove the contested file.
- Exclude the module cache directory from antivirus on-access scanning.
- Ensure sufficient memory/swap and avoid concurrent builds competing for the same cache.
Defensive patterns
Strategy: retry
Try / catch
// Retry Windows file-mapping failures that look like sharing violations.
for i := 0; i < 3; i++ {
err := runGoCmd()
if err == nil || !isSharingViolation(err) { return err }
time.Sleep(time.Duration(1<<i) * time.Second)
} Prevention
- Exclude the module cache from antivirus on-access scanning.
- Avoid running multiple `go` commands against the same cache concurrently.
- Periodically `go clean -modcache` to remove contested files.
When it happens
Trigger: The file is locked by another process (antivirus, editor, concurrent `go` process); system commit limit reached; file on a restricted network share.
Common situations: Antivirus scanning locks cache files; multiple concurrent builds; low virtual memory; SMB share permission limits.
Related errors
- MapViewOfFile %s: %w
- VirtualQuery %s: %w
- file URL encodes volume in host field: too few slashes?
- file URL missing drive letter
- %s and %s symbols must be in the same section
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/07ef5b7cdfd12e90.
Report an issue: GitHub.