Open
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>
Copilot
AI
changed the title
[WIP] Fix monitor command breaks due to ReadTimeout
Fix Monitor command blocking on ReadTimeout
Feb 20, 2026
🛡️ 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


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.