Fix: The issue of goroutine leakage when freeipmi is not installed #1245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
- 问题:
如果系统没有安装 freeipmi 相关命令,categraf 日志会持续报错 “executable file not found in $PATH”,同时进程线程数会不断增长,未被释放。
- 原因:
每次调用 Execute 时,都会调用 freeipmiConfigPipe 创建一个 goroutine,用于向 named pipe(FIFO 文件)写入 config 数据。
如果 freeipmi 相关命令不存在,exec.Command(cmd, args...).CombinedOutput() 会立即失败,不会读取 named pipe。
此时 goroutine 在尝试打开 named pipe (os.OpenFile) 时会阻塞,因为 FIFO 的写端没有被读端打开,OpenFile 无法返回。
由于外部命令没有启动(或启动失败),FIFO 的读端永远不会打开,写端的 goroutine 永远不会退出,导致线程/协程泄漏。
后续的逻辑:
即使 pipe 文件被删除,openFile 阻塞的 goroutine 也不会收到通知退出,还是会卡着。
- 解决:
在创建 pipe 和写 goroutine 前,先检查命令是否存在,避免无意义的 goroutine 启动。