{"record":{"id":"07ef5b7cdfd12e90","repo":"golang/go","slug":"createfilemapping-s-w","errorCode":null,"errorMessage":"CreateFileMapping %s: %w","messagePattern":"CreateFileMapping (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/mmap/mmap_windows.go","lineNumber":27,"sourceCode":"\t\"os\"\n\t\"syscall\"\n\t\"unsafe\"\n\n\t\"internal/syscall/windows\"\n)\n\nfunc mmapFile(f *os.File) (Data, error) {\n\tst, err := f.Stat()\n\tif err != nil {\n\t\treturn Data{}, err\n\t}\n\tsize := st.Size()\n\tif size == 0 {\n\t\treturn Data{f, nil}, nil\n\t}\n\th, err := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, 0, 0, nil)\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"CreateFileMapping %s: %w\", f.Name(), err)\n\t}\n\n\taddr, err := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, 0)\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"MapViewOfFile %s: %w\", f.Name(), err)\n\t}\n\tvar info windows.MemoryBasicInformation\n\terr = windows.VirtualQuery(addr, &info, unsafe.Sizeof(info))\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"VirtualQuery %s: %w\", f.Name(), err)\n\t}\n\tdata := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.RegionSize))\n\tif len(data) < int(size) {\n\t\t// In some cases, especially on 386, we may not receive a in incomplete mapping:\n\t\t// one that is shorter than the file itself. Return an error in those cases because\n\t\t// incomplete mappings are not useful.\n\t\treturn Data{}, fmt.Errorf(\"mmapFile: received incomplete mapping of file\")\n\t}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/mmap/mmap_windows.go#L9-L45","documentation":"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.","triggerScenarios":"The file is locked by another process (antivirus, editor, concurrent `go` process); system commit limit reached; file on a restricted network share.","commonSituations":"Antivirus scanning locks cache files; multiple concurrent builds; low virtual memory; SMB share permission limits.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Retry Windows file-mapping failures that look like sharing violations.\nfor i := 0; i < 3; i++ {\n    err := runGoCmd()\n    if err == nil || !isSharingViolation(err) { return err }\n    time.Sleep(time.Duration(1<<i) * time.Second)\n}","preventionTips":["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."],"tags":["go-toolchain","mmap","windows","file-lock"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}