Conversation
Co-authored-by: ndyakov <1547186+ndyakov@users.noreply.github.com>
Co-authored-by: ndyakov <1547186+ndyakov@users.noreply.github.com>
Co-authored-by: ndyakov <1547186+ndyakov@users.noreply.github.com>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
| } | ||
| cmd.ch <- line | ||
| } | ||
| } |
There was a problem hiding this comment.
Tight CPU-spinning loop when monitor status is idle
Low Severity
The original code called rd.Peek(1) unconditionally on every loop iteration regardless of status, which naturally blocked on I/O and prevented CPU spinning. The new code moves the Peek(1) call inside the if st == monitorStatusStart block. When status is monitorStatusIdle (between Monitor() creating the goroutine and the user calling Start()), the loop contains no blocking operation — it just checks context, reads status, and loops back immediately, consuming 100% of a CPU core.
|
Closing in favor of #3901, which addresses the root cause of #3079 by running MONITOR on a dedicated connection with no read deadline and propagating connection errors to the listener via the channel close + This patch keeps MONITOR on a pooled connection and swallows timeout errors with |


The Monitor command fails when
ReadTimeoutis reached, leaving channel listeners permanently blocked. The timeout error is caught but not propagated, and the channel is never closed.Changes
isTimeoutError(), treating them as expected behavior for long-running monitoring operationscloseChannel()helper withclosedflag to safely close the monitor channel exactly once when:Stop()is calledExample
The monitor continues operation across timeout boundaries while remaining stoppable via
Stop()or context cancellation.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.
Note
Medium Risk
Touches long-running goroutine/channel coordination in
Monitor, so regressions could cause leaks or premature channel closure, but changes are localized and covered by new tests.Overview
Fixes
Monitorto be resilient to socketReadTimeoutby treating timeout errors fromPeek/ReadStringas non-fatal and continuing the read loop.Improves lifecycle handling by adding a
closedflag pluscloseChannel()to ensure the monitor output channel is closed exactly once onStop(), context cancellation, or non-timeout errors, preventing callers from blocking indefinitely. Adds opt-in (env-gated) tests covering timeout behavior and context cancellation cleanup.Reviewed by Cursor Bugbot for commit 2c7e9a7. Bugbot is set up for automated code reviews on this repo. Configure here.