Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle large stdout and stderr lines from scripts #70

Merged
merged 3 commits into from
Sep 3, 2021

Conversation

Crevil
Copy link
Member

@Crevil Crevil commented Aug 31, 2021

Currently if a script outputs a single line to stdout or stderr over 16k
characters the script is stopped with a pipe error. When used in combination
with shell scripts this makes for a very confusing error state where output is
just limited or the process either hangs or fails without explanation.

This change replaces the shell executer based on github.com/go-cmd/cmd with one
using the standard libraries os/exec package. Further more the line buffer limit
is increased to 512k characters.

go-cmd does not support changing the maximum line length so the library cannot
support our use case.

This bug was found when a Go service was testing an HTML template. The test
would output the rendered HTML template and a complex SVG exceeded the current
16k limit. This resulted in the test being marked as successfull by the Go
toolchain but as the stdout pipe was broken shell scripts would not work as
intended.

Currently if a script outputs a single line to stdout or stderr over 16k
characters the script is stopped with a pipe error. When used in combination
with shell scripts this makes for a very confusing error state where output is
just limited or the process either hangs or fails without explanation.

This change replaces the shell executer based on github.com/go-cmd/cmd with one
using the standard libraries os/exec package. Further more the line buffer limit
is increased to 512k characters.

go-cmd does not support changing the maximum line length so the library cannot
support our use case.

This bug was found when a Go service was testing an HTML template. The test
would output the rendered HTML template and a complex SVG exceeded the current
16k limit. This resulted in the test being marked as successfull by the Go
toolchain but as the stdout pipe was broken shell scripts would not work as
intended.
@Crevil Crevil requested a review from a team August 31, 2021 12:23
@Crevil
Copy link
Member Author

Crevil commented Aug 31, 2021

I think this might break up the order of script's stdout and stderr. Hold on...

@Crevil
Copy link
Member Author

Crevil commented Sep 1, 2021

A couple of issues with this implementation. Using os/exec#CommandContext terminates the process with SIGKILL which means Docker does not clean up its containers. (a test case finds this bug 🙏 )

I'll have to give it some more work before its ready. Closing until then.

@Crevil Crevil closed this Sep 1, 2021
@Crevil Crevil reopened this Sep 1, 2021
Copy link
Member

@mahlunar mahlunar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@Crevil Crevil merged commit 48c5180 into master Sep 3, 2021
@Crevil Crevil deleted the fix/shell-script-line-limit branch September 3, 2021 11:24
@Crevil Crevil mentioned this pull request Mar 4, 2022
Crevil added a commit that referenced this pull request Mar 29, 2022
This change partially reverts 48c5180 (#70)
which fixed an issue where large outputs from shell scripts would break output
pipes (#90).

The change replaced go-cmd with a native implementation which on the surface
fixed the large output bug but introduced another subtle race condition in the
output of scripts.

The motivation in the original commit for replacing go-cmd was the missing
ability to configure the output buffers size. That feature is now available in
go-cmd why this change set reverts to use the proven go-cmd implementation. This
removes a lot of complexity from shuttle while also fixing the race condition
identified in #90.
Crevil added a commit that referenced this pull request Mar 29, 2022
This change partially reverts 48c5180 (#70)
which fixed an issue where large outputs from shell scripts would break output
pipes (#90).

The change replaced go-cmd with a native implementation which on the surface
fixed the large output bug but introduced another subtle race condition in the
output of scripts.

The motivation in the original commit for replacing go-cmd was the missing
ability to configure the output buffers size. That feature is now available in
go-cmd why this change set reverts to use the proven go-cmd implementation. This
removes a lot of complexity from shuttle while also fixing the race condition
identified in #90.
Crevil added a commit that referenced this pull request Mar 30, 2022
This change partially reverts 48c5180 (#70)
which fixed an issue where large outputs from shell scripts would break output
pipes (#90).

The change replaced go-cmd with a native implementation which on the surface
fixed the large output bug but introduced another subtle race condition in the
output of scripts.

The motivation in the original commit for replacing go-cmd was the missing
ability to configure the output buffers size. That feature is now available in
go-cmd why this change set reverts to use the proven go-cmd implementation. This
removes a lot of complexity from shuttle while also fixing the race condition
identified in #90.
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.

2 participants