larksuite/cli · error
cannot restore blocking mode: %w
Error message
cannot restore blocking mode: %w
What it means
After validating the fd, the library must switch it back from O_NONBLOCK (set only so a FIFO open cannot wedge the process) to normal blocking mode via syscall.SetNonblock. This fcntl call failed, so the fd cannot be guaranteed to behave like a normal blocking file and the open is abandoned. Practically this requires the fd to have become invalid between open and the call.
Source
Thrown at internal/vfs/localfileio/openvalidated_unix.go:76
func inspectOpenedFile(f *os.File, pre os.FileInfo, rejectHardLinks bool) error {
post, err := f.Stat()
if err != nil {
return fmt.Errorf("cannot stat opened file: %w", err)
}
if pre != nil && !os.SameFile(pre, post) {
return fmt.Errorf("file changed between validation and open")
}
if !post.Mode().IsRegular() {
return fmt.Errorf("not a regular file (directories, devices, FIFOs, and sockets are refused)")
}
if rejectHardLinks {
if st, ok := post.Sys().(*syscall.Stat_t); ok && st.Nlink > 1 {
return fmt.Errorf("file has multiple hard links, so the other names it can be reached by " +
"cannot be checked (hint: copy the file and use the copy instead)")
}
}
if err := syscall.SetNonblock(int(f.Fd()), false); err != nil {
return fmt.Errorf("cannot restore blocking mode: %w", err)
}
return nil
}
View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Eliminate concurrent Close of the *os.File in your code
- Check the wrapped errno in the %w cause (EBADF → fd lifecycle bug in your process)
- Retry the operation; a one-off transient is possible
- Report if reproducible on a standard local filesystem — a healthy open should never fail here
Defensive patterns
Strategy: retry
Try / catch
var pve *fileio.PathValidationError
if errors.As(err, &pve) { /* fd-validation class failure; errno in pve.Unwrap() decides retry vs bug */ } Prevention
- Do not Close *os.File values concurrently with the open call that returned them
- Treat repeated occurrences as a process fd-lifecycle bug, not a CLI defect
- Keep fd limits healthy so fcntl is not stressed near exhaustion
When it happens
Trigger: syscall.SetNonblock(fd, false) returns an error — essentially only when the fd is invalid/closed at that instant (concurrent Close racing the validation, EBADF) or an exotic filesystem rejects the fcntl.
Common situations: Same concurrency bug pattern as the fstat failure: user code or a finalizer closing the *os.File mid-openValidated; fd-table corruption or resource-limit pressure at fcntl time.
Related errors
- %w (lock: %s, syscall: %v)
- cannot stat opened file: %w
- file changed between validation and open
- not a regular file (directories, devices, FIFOs, and sockets
- file has multiple hard links, so the other names it can be r
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/63337ef4f0ccda09.
Report an issue: GitHub.