Skip to content

Conversation

lifa1225
Copy link
Contributor

- 问题:
如果系统没有安装 freeipmi 相关命令,categraf 日志会持续报错 “executable file not found in $PATH”,同时进程线程数会不断增长,未被释放。

28642268227d74994d091d0799deac4 6c081941cc1b9ebf0ecbde4895e5299

- 原因:
每次调用 Execute 时,都会调用 freeipmiConfigPipe 创建一个 goroutine,用于向 named pipe(FIFO 文件)写入 config 数据。
如果 freeipmi 相关命令不存在,exec.Command(cmd, args...).CombinedOutput() 会立即失败,不会读取 named pipe。
此时 goroutine 在尝试打开 named pipe (os.OpenFile) 时会阻塞,因为 FIFO 的写端没有被读端打开,OpenFile 无法返回。
由于外部命令没有启动(或启动失败),FIFO 的读端永远不会打开,写端的 goroutine 永远不会退出,导致线程/协程泄漏。
后续的逻辑:

defer func() {
		if err := os.Remove(pipe); err != nil {
			log.Println("msg", "Error deleting named pipe", "error", err)
		}
	}()

即使 pipe 文件被删除,openFile 阻塞的 goroutine 也不会收到通知退出,还是会卡着。

- 解决:
在创建 pipe 和写 goroutine 前,先检查命令是否存在,避免无意义的 goroutine 启动。

if _, err := exec.LookPath(cmd); err != nil {
		return Result{nil, fmt.Errorf("executable %s not found in $PATH", cmd)}
	}

@kongfei605
Copy link
Collaborator

Thank you @lifa1225

@kongfei605 kongfei605 merged commit 82252ff into flashcatcloud:main Jun 17, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants