{"record":{"id":"78941dcf6244df67","repo":"larksuite/cli","slug":"unlock-file-w","errorCode":null,"errorMessage":"unlock file: %w","messagePattern":"unlock file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/lockfile/lockfile.go","lineNumber":73,"sourceCode":"\t}\n\tif err := tryLockFile(f); err != nil {\n\t\tf.Close()\n\t\treturn err\n\t}\n\tl.file = f\n\treturn nil\n}\n\n// Unlock keeps the file on disk to avoid inode-reuse races between unlock and competing open+flock.\nfunc (l *LockFile) Unlock() error {\n\tif l.file == nil {\n\t\treturn nil\n\t}\n\terr := unlockFile(l.file)\n\tcloseErr := l.file.Close()\n\tl.file = nil\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unlock file: %w\", err)\n\t}\n\treturn closeErr\n}\n\nfunc (l *LockFile) Path() string {\n\treturn l.path\n}\n","sourceCodeStart":55,"sourceCodeEnd":81,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/lockfile/lockfile.go#L55-L81","documentation":"Unlock releases the OS byte-range lock and closes the file; if unlockFile's syscall fails the error is wrapped as \"unlock file: %w\". This is rare since locks auto-release on process exit, but indicates the handle state is inconsistent.","triggerScenarios":"Calling Unlock() when the underlying unlock syscall fails (Windows UnlockFileEx error, invalid/closed handle, or an OS-level failure), after the file was non-nil.","commonSituations":"File descriptor already closed elsewhere (double-close, external Close of the same handle); OS resource errors; platform syscall failures after system suspend/resume.","solutions":["Check the wrapped cause; if it is \"file already closed\", audit for double-Close of the handle in your code.","Never close l.file independently; use only LockFile.Unlock()/Release.","On failure, rely on process-exit auto-release and restart the operation cleanly.","Recreate the LockFile via ForSubscribe/New for the next acquisition."],"exampleFix":"// before\nlf.Unlock()\nf.Close() // extra close corrupts handle state\n// after\nlf.Unlock()\n// do not touch the underlying file directly","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := lf.Unlock(); err != nil {\n    log.Printf(\"unlock failed (will auto-release on exit): %v\", err)\n}","preventionTips":["Only release via LockFile.Unlock/Release; never Close the handle yourself","Avoid double-Unlock/double-Close paths","Treat unlock failure as recoverable — OS releases locks at process exit"],"tags":["file-locking","io","windows"],"backgroundTag":"file-lock-contention","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}