larksuite/cli · warning
unlock file: %w
Error message
unlock file: %w
What it means
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.
Source
Thrown at internal/lockfile/lockfile.go:73
}
if err := tryLockFile(f); err != nil {
f.Close()
return err
}
l.file = f
return nil
}
// Unlock keeps the file on disk to avoid inode-reuse races between unlock and competing open+flock.
func (l *LockFile) Unlock() error {
if l.file == nil {
return nil
}
err := unlockFile(l.file)
closeErr := l.file.Close()
l.file = nil
if err != nil {
return fmt.Errorf("unlock file: %w", err)
}
return closeErr
}
func (l *LockFile) Path() string {
return l.path
}
View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before lf.Unlock() f.Close() // extra close corrupts handle state // after lf.Unlock() // do not touch the underlying file directly
Defensive patterns
Strategy: try-catch
Try / catch
if err := lf.Unlock(); err != nil {
log.Printf("unlock failed (will auto-release on exit): %v", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: File descriptor already closed elsewhere (double-close, external Close of the same handle); OS resource errors; platform syscall failures after system suspend/resume.
Related errors
- %w (lock: %s, syscall: %v)
- invalid chart size: {size!r}
- failed to read input: %w
- input terminated unexpectedly (EOF)
- app registration failed: read body: %w
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/78941dcf6244df67.
Report an issue: GitHub.