-
Notifications
You must be signed in to change notification settings - Fork 261
Description
🟡 medium - bug
File: cmd/root/api.go (line 90)
Code
go func() {
select {
case <-ctx.Done():
case <-done:
}
stdin.Close()
}()Problem
The stdin.Close() call inside the goroutine is intended to unblock the stdin.Read(buf) call. However, if the monitorStdin function returns (e.g., due to an error in stdin.Read) before the ctx.Done() or done channels are closed, the goroutine might remain active, holding onto the stdin file descriptor. This could lead to a resource leak if stdin is not closed by the main thread.
Suggested Fix
Ensure that stdin is always closed when the monitorStdin function returns, possibly by adding a defer stdin.Close() in the monitorStdin function itself, or by explicitly closing stdin in the main runAPICommand function after monitorStdin is no longer needed. The current defer close(done) only closes the channel, not the file.
Found by nightly codebase scan