go io_error ai_generated true

remove /tmp/locked.txt: device or resource busy

ID: go/os-remove-file-in-use

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-07-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.19 active

Root Cause

Attempting to delete a file that is currently open by another process or the same process.

generic

中文

尝试删除当前被其他进程或同一进程打开的文件。

Workarounds

  1. 95% success
    if err := file.Close(); err != nil { return err }; if err := os.Remove(path); err != nil { return err }
  2. 80% success
    Use os.Rename to a temporary name then remove

Dead Ends

Common approaches that don't work:

  1. 70% fail

    File remains, causing resource leak

  2. 90% fail

    RemoveAll also fails if file is busy