{"record":{"id":"d0606d4ef06ae22b","repo":"vitessio/vitess","slug":"unable-to-close-file-v","errorCode":null,"errorMessage":"unable to close file: %v","messagePattern":"unable to close file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/backupengine.go","lineNumber":767,"sourceCode":"\t\treturn err\n\t}\n\treturn nil\n}\n\n// create restore state file\nfunc createStateFile(cnf *Mycnf) error {\n\t// if we start writing content to this file:\n\t// change RD_ONLY to RDWR\n\t// change Create to Open\n\t// rename func to openStateFile\n\t// change to return a *File\n\tfname := filepath.Join(cnf.TabletDir(), RestoreState)\n\tfd, err := os2.Create(fname)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to create file: %v\", err)\n\t}\n\tif err = fd.Close(); err != nil {\n\t\treturn fmt.Errorf(\"unable to close file: %v\", err)\n\t}\n\treturn nil\n}\n\n// delete restore state file\nfunc removeStateFile(cnf *Mycnf) error {\n\tfname := filepath.Join(cnf.TabletDir(), RestoreState)\n\tif err := os.Remove(fname); err != nil {\n\t\treturn fmt.Errorf(\"unable to delete file: %v\", err)\n\t}\n\treturn nil\n}\n\n// RestoreWasInterrupted tells us whether a previous restore\n// was interrupted and we are now retrying it\nfunc RestoreWasInterrupted(cnf *Mycnf) bool {\n\tname := filepath.Join(cnf.TabletDir(), RestoreState)\n\t_, err := os.Stat(name)","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/backupengine.go#L749-L785","documentation":"Thrown by createStateFile when closing the just-created restore state file descriptor fails. Rare — typically indicates a filesystem/I/O error (some filesystems surface ENOSPC or write-back errors at close) or an interrupted file operation.","triggerScenarios":"os2.Create succeeded but fd.Close() returns a non-nil error during the restore preparation step.","commonSituations":"Full disk where write-back fails at close; underlying storage errors (NFS/EBS hiccups); extremely rare local-disk edge cases.","solutions":["Inspect the wrapped error and check disk space and filesystem health on the tablet-dir volume.","Re-run the restore once storage is healthy — state file creation is retried on the next attempt.","Check dmesg/storage logs for I/O errors on the host."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := checkDiskSpace(cnf.TabletDir(), minFreeBytes); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := restore(); err != nil {\n    if strings.Contains(err.Error(), \"unable to close file\") {\n        // verify filesystem health/disk space, then retry the restore once\n        return retryRestore()\n    }\n    return err\n}","preventionTips":["Monitor disk space and I/O errors on hosts running restores.","Use local/reliable storage for tablet dirs rather than flaky network filesystems.","Re-run restore on transient storage failures after verifying disk health."],"tags":["filesystem","restore","io","disk"],"backgroundTag":"file-close-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}