{"record":{"id":"63337ef4f0ccda09","repo":"larksuite/cli","slug":"cannot-restore-blocking-mode-w","errorCode":null,"errorMessage":"cannot restore blocking mode: %w","messagePattern":"cannot restore blocking mode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/vfs/localfileio/openvalidated_unix.go","lineNumber":76,"sourceCode":"func inspectOpenedFile(f *os.File, pre os.FileInfo, rejectHardLinks bool) error {\n\tpost, err := f.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot stat opened file: %w\", err)\n\t}\n\tif pre != nil && !os.SameFile(pre, post) {\n\t\treturn fmt.Errorf(\"file changed between validation and open\")\n\t}\n\tif !post.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file (directories, devices, FIFOs, and sockets are refused)\")\n\t}\n\tif rejectHardLinks {\n\t\tif st, ok := post.Sys().(*syscall.Stat_t); ok && st.Nlink > 1 {\n\t\t\treturn fmt.Errorf(\"file has multiple hard links, so the other names it can be reached by \" +\n\t\t\t\t\"cannot be checked (hint: copy the file and use the copy instead)\")\n\t\t}\n\t}\n\tif err := syscall.SetNonblock(int(f.Fd()), false); err != nil {\n\t\treturn fmt.Errorf(\"cannot restore blocking mode: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":58,"sourceCodeEnd":80,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/vfs/localfileio/openvalidated_unix.go#L58-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var pve *fileio.PathValidationError\nif errors.As(err, &pve) { /* fd-validation class failure; errno in pve.Unwrap() decides retry vs bug */ }","preventionTips":["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"],"tags":["filesystem","fcntl","unix","concurrency"],"backgroundTag":"fcntl-nonblock-failed","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"}