Skip to content

Fix: share bufio.Scanner across ExecuteCommand calls#72

Merged
mirkoboehm merged 1 commit intomainfrom
wip/mirko-71-ExecuteCommand-hangs
Mar 31, 2026
Merged

Fix: share bufio.Scanner across ExecuteCommand calls#72
mirkoboehm merged 1 commit intomainfrom
wip/mirko-71-ExecuteCommand-hangs

Conversation

@mirkoboehm
Copy link
Copy Markdown
Owner

bufio.NewScanner wraps the stdout pipe in an internal 4096-byte read-ahead buffer. Creating a new Scanner on each ExecuteCommand call discards any bytes already buffered from the previous call, causing the next command's BEGIN_MARKER to be lost and the goroutine to block indefinitely waiting for output that was already consumed.

Fix by creating the Scanner once in StartShell and reusing it for the lifetime of the shell process.

@mirkoboehm mirkoboehm self-assigned this Mar 31, 2026
bufio.NewScanner wraps the stdout pipe in an internal 4096-byte
read-ahead buffer. Creating a new Scanner on each ExecuteCommand call
discards any bytes already buffered from the previous call, causing
the next command's BEGIN_MARKER to be lost and the goroutine to block
indefinitely waiting for output that was already consumed.

Fix by creating the Scanner once in StartShell and reusing it for the
lifetime of the shell process.

Closes #71
@mirkoboehm mirkoboehm force-pushed the wip/mirko-71-ExecuteCommand-hangs branch from efe6dfa to 3c2c9c2 Compare March 31, 2026 15:38
@mirkoboehm mirkoboehm merged commit 8f74505 into main Mar 31, 2026
2 checks passed
@mirkoboehm mirkoboehm deleted the wip/mirko-71-ExecuteCommand-hangs branch March 31, 2026 15:39
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.

1 participant