{"record":{"id":"56438a0d299e0a2a","repo":"Billionmail/BillionMail","slug":"failed-to-write-temporary-output-file-v","errorCode":null,"errorMessage":"failed to write temporary output file: %v","messagePattern":"failed to write temporary output file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/multi_ip_domain/config_manager.go","lineNumber":219,"sourceCode":"\t\tif gfile.Exists(tempDockerComposePath) {\n\t\t\tos.Remove(tempDockerComposePath)\n\t\t\tg.Log().Debugf(ctx, \"Cleaned up temporary file: %s\", tempDockerComposePath)\n\t\t}\n\t}()\n\n\tg.Log().Debugf(ctx, \"Successfully read docker-compose.yml file, size: %d bytes\", len(content))\n\tnewContent, err := m.modifyDockerComposeText(ctx, content, configs)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to modify docker-compose content: %v\", err)\n\t}\n\n\t// Step 7: Write new file docker-compose_addnetwork.yml\n\ttempOutputPath := filepath.Join(containerDataPath, \"temp_docker-compose_addnetwork.yml\")\n\thostTempOutputPath := filepath.Join(hostDataPath, \"temp_docker-compose_addnetwork.yml\")\n\n\t// First write to temporary container file\n\tif err := gfile.PutContents(tempOutputPath, newContent); err != nil {\n\t\treturn fmt.Errorf(\"failed to write temporary output file: %v\", err)\n\t}\n\n\t// 然后从宿主机临时位置复制到最终目标位置\n\tcopyOutputCmd := []string{\n\t\t\"/bin/sh\", \"-c\",\n\t\tfmt.Sprintf(`chroot /host_root cp \"%s\" \"%s\"`, hostTempOutputPath, outputPath),\n\t}\n\n\tresult, err = dk.ExecHostCommand(ctx, copyOutputCmd)\n\tif err != nil || result.ExitCode != 0 {\n\t\tif gfile.Exists(tempOutputPath) {\n\t\t\tos.Remove(tempOutputPath)\n\t\t}\n\t\treturn gerror.New(\"failed to copy output file to destination\")\n\t}\n\n\t// Cleanup temporary output file\n\tif gfile.Exists(tempOutputPath) {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/multi_ip_domain/config_manager.go#L201-L237","documentation":"After modification, the new compose content is written to the container-side temp file (temp_docker-compose_addnetwork.yml) so it can be chroot-copied to the final docker-compose_addnetwork.yml on the host. If gfile.PutContents fails, the update aborts and rollback runs. This is a local filesystem write failure inside the container.","triggerScenarios":"gfile.PutContents(tempOutputPath, newContent) fails: disk full, directory permissions, read-only filesystem, or the directory was removed between creation and write.","commonSituations":"core/data volume filled up (temp copies accumulate on errors); non-root process lacking write permission; volume unmounted mid-operation.","solutions":["Check the wrapped %v OS error; free disk space on the core/data volume (df -h) and delete stale temp_* files.","Fix ownership/permissions of the container data directory for the running process user.","Verify the volume is mounted writable (docker inspect) and remount if read-only.","Retry ApplyConfigsWithRollback once the filesystem condition is resolved."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"dir := public.AbsPath(\"../core/data\")\nif err := syscall.Access(dir, os.O_WRONLY); err != nil {\n\treturn fmt.Errorf(\"temp dir %s not writable: %v\", dir, err)\n}\nout, _ := exec.Command(\"df\", \"-h\", dir).Output()\n_ = out // ensure adequate free space","typeGuard":null,"tryCatchPattern":"if err := mgr.ApplyConfigsWithRollback(ctx, configs); err != nil {\n\tif strings.Contains(err.Error(), \"failed to write temporary output file\") {\n\t\t// clean stale temp_* files, free space, fix permissions, retry\n\t}\n}","preventionTips":["Schedule cleanup of stale temp_* files in core/data.","Monitor disk usage on the core-data volume.","Keep the data directory writable by the service account.","Unmount/remount volumes only outside apply windows."],"tags":["filesystem","disk","docker-compose","go"],"backgroundTag":"temp-file-write-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}