Repository navigation
Return system.run when the shell exits, not when its pipes close - #26
Merged
shaeberling merged 1 commit intoOct 5, 2026
Merged
Conversation
The first communicate() in system_run waited for stdout and stderr EOF, not for the shell process. PR facebookincubator#3 only bounded the grace wait after a timeout kill. A command that daemonizes and exits 0 while a child still holds the inherited pipes (setsid sleep 30 &) therefore burned the full timeout, killpg raised ProcessLookupError because bash was already gone, and the grace communicate timed out too. The call returned timed_out with exit code 0 and blocked the gadget command loop for the whole timeout. Wait for the shell itself. If it exits in time, drain only the bytes already queued on the pipes and return that exit code with timed_out false. If it does not, keep the existing kill-and-grace path.
shaeberling
self-requested a review
October 5, 2026 21:41
shaeberling
added a commit
that referenced
this pull request
Oct 5, 2026
_read_available, added in #26, reads until a pipe is empty or closed and never checks the time. A writer that outpaces the reads could keep it looping past the command's timeout, and the read after the shell exits had no limit at all. Stop at the command's deadline while it runs, and after DRAIN_S (0.5 s) once the shell has exited.
blacksamuraiiii
pushed a commit
to blacksamuraiiii/muse-esp32-s3-touch-lcd-1.85b
that referenced
this pull request
Nov 3, 2026
_read_available, added in facebookincubator#26, reads until a pipe is empty or closed and never checks the time. A writer that outpaces the reads could keep it looping past the command's timeout, and the read after the shell exits had no limit at all. Stop at the command's deadline while it runs, and after DRAIN_S (0.5 s) once the shell has exited.
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.
Hey @anantn ,
Problem
PR #3 was a partial fix: it bounded only the after-kill grace wait. The first
communicate()inExecutor.system_runstill waits for stdout and stderr EOF, not for the shell to exit.A command that daemonizes and exits 0 while a child holds the inherited pipes keeps those pipes open.
communicate()burns the full timeout,killpgthen raisesProcessLookupErrorbecause bash is already gone, and the grace wait also times out. The gadget reports failure for a command that succeeded and blocks the command loop for the whole timeout (default 120s, max 600s).Reproduction on
main:returns after about 4 seconds with
timed_out: trueandexit_code: 0.Fix
Wait for the shell process itself, and read only bytes already queued on the pipes. If the shell exits in time, return
timed_out: falseand its real exit code, without callingcommunicate()in a way that waits for EOF. If it does not exit, the kill-and-grace path from PR #3 is unchanged.Test
test_system_run_returns_when_the_shell_exits_but_a_child_holds_the_pipesrunssetsid sleep 30 &with a 2000 ms timeout and asserts it returns in under a second withtimed_outfalse andexit_code0. It also checks thatecho histill returns stdout and exit 0, and thatsleep 30with a 300 ms timeout still reportstimed_out. Onmainthat test fails in 4.04s (exit_code0 andtimed_outtrue). With this change,pytest tests/test_executor.pyis 13 passed and the linux suite is 138 passed.Not tested on a real device, over BLE or against the Muse service. Only the unit suite.