-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix the hanging problem in windows if the terraform plan command failed #5909
fix the hanging problem in windows if the terraform plan command failed #5909
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mohamed! Left a few minor comments but LGTM
samcli/lib/utils/subprocess_utils.py
Outdated
@@ -92,10 +96,18 @@ def _print_loading_pattern(): | |||
# we read from subprocess stdout to avoid the deadlock process.wait function | |||
# for more detail check this python bug https://bugs.python.org/issue1256 | |||
for line in process.stdout: | |||
decoded_line = _check_and_process_bytes(line) | |||
is_error = ( | |||
not IS_NOT_WINDOWS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we maybe flip the constant to clean up this condition? I think it would make it easier to read since this double negative reads a little awkward.
IS_WINDOWS
instead of IS_NOT_WINDOWS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this issue @moelasmar!
One other thing I was wondering is setting some timeout to the process calls that we are making. Can we add some timeouts for them so that we won't be waiting indefinitely?
samcli/lib/utils/subprocess_utils.py
Outdated
is_error = ( | ||
IS_WINDOWS | ||
and len(line) >= len(TERRAFORM_ERROR_PREFIX) | ||
and line[0:4] == bytes(TERRAFORM_ERROR_PREFIX) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This utility module and function seems very generic, can we put terraform specific stuff behind a flag so that this will be only applied to the places where it is been called for terraform stuff?
In windows, if Terraform plan command failed, the std out stream will not be closed till we read all the logs in the std err stream. The solution is to redirect the Terraform plan subprocess stderr stream to write in stdout, so we can read all the plan command logs from stdout, and we do not need to switch to the stderr in case if the command failed. This change only applied for Windows. I also added a check to differentiate between the plan command normal output, and errors.
I added a new integration test case to make sure that SAM CLI will not hang in case if terraform plan command failed.
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.