Repository navigation
engine: fix goroutine leaks + deadlock in terminal - #9013
Merged
Merged
Conversation
Rather than allocating a new byte slice for every read from stdout/stderr sent to clients, we can re-use the same byte slice. This reduces the amount of allocations the engine does. Not a world-changing optimization but I have seen similar fixes in other contexts make a noticeable difference in CPU usage since the Go runtime has a lot less work to do. Signed-off-by: Erik Sipsma <[email protected]>
Before this, every interactive debug terminal container would leak multiple goroutines due to various io pipes not getting closed. In one particular codepath, the read-side of the stdout io.Pipe would be left open while the other side was in the middle of a write, which caused the executor code to block forever and never return. This manifested as an occasional flake in the TestModule/TestDaggerTerminal/on_failure test case. Additionally, the part of that test case which meant to assert on handling of --interactive-command values which didn't exist was not checking error values. It was hitting an error due to the fact that it didn't have a TTY setup rather than the error around the command not existing. That test case is fixed now to setup a TTY and verify the error message is the expected one. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
fix-terminal-error-leaks
branch
from
November 21, 2024 00:03
2d49491 to
9d9885a
Compare
jedevc
approved these changes
Nov 21, 2024
gerhard
approved these changes
Nov 21, 2024
gerhard
left a comment
Contributor
There was a problem hiding this comment.
This must have been a pain to track down & fix. LGTM!
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.
Fixes #8554
While running some tests locally for the (unrelated) filesync PR I accidentally stumbled on a set of tests to run that coincidentally repro'd the flake in #8554 pretty consistently locally:
I would hit the flake where the
on_failuretest hung after 3-4 counts pretty consistently. The set of tests most likely just happens to tweak timing on my machine in just the right way that the race conditions it was caused by would get triggered more often.There were multiple problems from the test case down through the engine, described in the commit below.
With this fix in place I can't repro the flake locally anymore. Additionally, after running the terminal tests and sending SIGQUIT to the engine I previously saw a ton of leaked goroutines; now after this change they are all gone.
I also included a small one-line performance fix that I noticed while going through the code here.
engine: fix goroutine leaks + deadlock in terminal
Before this, every interactive debug terminal container would leak
multiple goroutines due to various io pipes not getting closed. In one
particular codepath, the read-side of the stdout io.Pipe would be left
open while the other side was in the middle of a write, which caused the
executor code to block forever and never return. This manifested as an
occasional flake in the TestModule/TestDaggerTerminal/on_failure test
case.
Additionally, the part of that test case which meant to assert on
handling of --interactive-command values which didn't exist was not
checking error values. It was hitting an error due to the fact that it
didn't have a TTY setup rather than the error around the command not
existing. That test case is fixed now to setup a TTY and verify the
error message is the expected one.
Signed-off-by: Erik Sipsma [email protected]
engine: slightly optimize terminal reading by reusing buffers
Rather than allocating a new byte slice for every read from
stdout/stderr sent to clients, we can re-use the same byte slice.
This reduces the amount of allocations the engine does. Not a
world-changing optimization but I have seen similar fixes in other
contexts make a noticeable difference in CPU usage since the Go runtime
has a lot less work to do.
Signed-off-by: Erik Sipsma [email protected]