{"record":{"id":"4bee3b03c4dc8d53","repo":"containerd/containerd","slug":"failed-to-create-s-temp-file-w","errorCode":null,"errorMessage":"failed to create '%s' temp file: %w","messagePattern":"failed to create '(.+?)' temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/snapshots/lcow/lcow.go","lineNumber":470,"sourceCode":"\n\t\tscratchTempName := fmt.Sprintf(\"scratch-%s-tmp.vhdx\", strconv.Itoa(int(1e9 + r%1e9))[1:])\n\t\tscratchTempPath := filepath.Join(s.root, scratchTempName)\n\n\t\t// Create the scratch\n\t\trhcs := runhcs.Runhcs{\n\t\t\tDebug:     true,\n\t\t\tLog:       filepath.Join(s.root, \"runhcs-scratch.log\"),\n\t\t\tLogFormat: runhcs.JSON,\n\t\t\tOwner:     \"containerd\",\n\t\t}\n\n\t\topt := runhcs.CreateScratchOpts{\n\t\t\tSizeGB: sizeGB,\n\t\t}\n\n\t\tif err := rhcs.CreateScratchWithOpts(ctx, scratchTempPath, &opt); err != nil {\n\t\t\tos.Remove(scratchTempPath)\n\t\t\treturn nil, fmt.Errorf(\"failed to create '%s' temp file: %w\", scratchTempName, err)\n\t\t}\n\t\tif err := os.Rename(scratchTempPath, scratchFinalPath); err != nil {\n\t\t\tos.Remove(scratchTempPath)\n\t\t\treturn nil, fmt.Errorf(\"failed to rename '%s' temp file to 'scratch.vhdx': %w\", scratchTempName, err)\n\t\t}\n\t\tscratchSource, err = os.OpenFile(scratchFinalPath, os.O_RDONLY, 0700)\n\t\tif err != nil {\n\t\t\tos.Remove(scratchFinalPath)\n\t\t\treturn nil, fmt.Errorf(\"failed to open scratch.vhdx for read after creation: %w\", err)\n\t\t}\n\t} else {\n\t\tlog.G(ctx).Debugf(\"scratch vhd %s was already present. Retrieved from cache\", vhdFileName)\n\t}\n\treturn scratchSource, nil\n}\n\nfunc (s *snapshotter) parentIDsToParentPaths(parentIDs []string) []string {\n\tvar parentLayerPaths []string","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/plugins/snapshots/lcow/lcow.go#L452-L488","documentation":"Thrown by openOrCreateScratch when runhcs.CreateScratchWithOpts fails to create the temporary scratch VHD file. The temp file is removed and the underlying runhcs error (typically a runhcs invocation failure) is wrapped. This means the Hyper-V/container host tooling could not produce a blank scratch.vhdx of the requested size.","triggerScenarios":"rhcs.CreateScratchWithOpts(ctx, scratchTempPath, &opt) returns an error while creating a new scratch VHD (missing or broken runhcs.exe, Hyper-V not enabled, invalid sizeGB, insufficient disk space).","commonSituations":"Running LCOW containers on a Windows host without the Hyper-V feature/Host Compute Service installed; runhcs version mismatch with containerd; disk-full on the snapshot volume; requesting a scratch size larger than the available disk.","solutions":["Verify runhcs.exe is present and functional on PATH (run `runhcs --version`) and matches your containerd version","Enable required Windows features: Hyper-V and Containers (Install-WindowsFeature Hyper-V, Containers)","Free disk space on the volume hosting the snapshot root or reduce the requested sizeGB","Check the wrapped runhcs error output in logs for the concrete Win32/HCS failure code"],"exampleFix":"// before: LCOW snapshotter on host without Hyper-V\nInstall-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart\n// after: scratch creation succeeds via runhcs","handlingStrategy":"retry","validationCode":"const hyperVReady = await run('powershell -c \"(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State\"')\nif (!hyperVReady.includes('Enabled')) throw new Error('Enable Hyper-V before LCOW snapshots')\nconst freeGB = await getFreeDiskGB(snapshotRoot)\nif (freeGB < requestedSizeGB * 1.1) throw new Error('insufficient disk space for scratch creation')","typeGuard":"function isRunhcsError(e: unknown): e is Error & { stderr?: string } {\n  return e instanceof Error && 'stderr' in e\n}","tryCatchPattern":"try {\n  await createSnapshotWithScratch(sizeGB)\n} catch (err) {\n  if (isTransient(err)) return retryWithBackoff(err)\n  log.error('scratch creation failed; verify runhcs and Hyper-V', err)\n  throw err\n}","preventionTips":["Verify runhcs.exe availability and version parity with containerd at install time","Enable Hyper-V/Containers features before deploying LCOW workloads","Alert on snapshot-volume free space below the largest configured scratch size","Capture runhcs stderr in logs for concrete failure codes"],"tags":["windows","lcow","vhd","runhcs"],"backgroundTag":"vhd-creation-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}