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

Drain stdout pipe while command is running #614

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

jflan-dd
Copy link
Contributor

@jflan-dd jflan-dd commented Jul 12, 2024

One of the commands we called as part of a Danger plugin ended up generating more output that the Pipe's buffer could hold. This resulted in Danger locking up and blocking CI.

This change moves reading from stdin to before the task has exited so that the Pipe does not get too full.

You can test this change will the following code:

let shell = ShellExecutor()
let result = try shell.spawn("hexdump /dev/urandom | head -c 500000", arguments: [])

I thought about adding a test, but if the test were to ever go wrong it would lock up CI instead of failing

@jflan-dd
Copy link
Contributor Author

@f-meloni Could you review this when you have a chance?


let data = pipe.fileHandleForReading.readDataToEndOfFile()

task.waitUntilExit()
Copy link
Member

Choose a reason for hiding this comment

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

Would you still receive all the text output coming from the executed shell command after this change?
Given we are reading before the task ends

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're calling readDataToEndOfFile() so we'll get the entire output of the command from the pipe before continuing to task.waitUntilExit(), which I assume will basically immediately complete at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@f-meloni does that seem correct?

Copy link
Member

Choose a reason for hiding this comment

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

Let's give it a chance :)

Copy link
Member

@f-meloni f-meloni left a comment

Choose a reason for hiding this comment

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

Would you mind please updating the Changelog before merging? Thank you

@f-meloni f-meloni merged commit b22f43c into danger:master Oct 14, 2024
@jflan-dd jflan-dd deleted the jflan/pipe-overfill branch October 15, 2024 17:02
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