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
Changes
Monitor’s long-running read loop and channel lifecycle, which can affect concurrency behavior and how callers detect termination (channel now closes on stop/cancel/errors). The scope is limited to the monitor command but touches goroutine/locking/error-handling paths.Overview
Fixes
MONITORhanging/breaking whenReadTimeoutis hit. The monitor read loop now treats timeout errors fromPeek/ReadStringas transient and continues reading instead of exiting.Adds deterministic shutdown semantics.
MonitorCmdtracks whether the user-provided channel has been closed and closes it exactly once whenStop()is requested, the parent context is cancelled, or a non-timeout read error occurs.Adds manual tests in
monitor_test.goto cover operation across timeouts and cleanup on context cancellation (guarded byRUN_MONITOR_TEST).Written by Cursor Bugbot for commit 6a48d3b. This will update automatically on new commits. Configure here.