go
io_error
ai_generated
true
删除 /tmp/locked.txt: 设备或资源忙
remove /tmp/locked.txt: device or resource busy
ID: go/os-remove-file-in-use
80%修复率
86%置信度
0证据数
2025-07-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
根因分析
尝试删除当前被其他进程或同一进程打开的文件。
English
Attempting to delete a file that is currently open by another process or the same process.
解决方案
-
95% 成功率
if err := file.Close(); err != nil { return err }; if err := os.Remove(path); err != nil { return err } -
80% 成功率
Use os.Rename to a temporary name then remove
无效尝试
常见但无效的做法:
-
70% 失败
File remains, causing resource leak
-
90% 失败
RemoveAll also fails if file is busy