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

fix the hanging problem in windows if the terraform plan command failed #5909

Merged
merged 9 commits into from
Sep 14, 2023

Conversation

moelasmar
Copy link
Contributor

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

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@moelasmar moelasmar marked this pull request as ready for review September 8, 2023 10:19
@moelasmar moelasmar requested a review from a team as a code owner September 8, 2023 10:19
Copy link
Contributor

@mildaniel mildaniel left a 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 Show resolved Hide resolved
samcli/lib/utils/subprocess_utils.py Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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

Copy link
Contributor

@mndeveci mndeveci left a 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 Show resolved Hide resolved
Comment on lines 99 to 103
is_error = (
IS_WINDOWS
and len(line) >= len(TERRAFORM_ERROR_PREFIX)
and line[0:4] == bytes(TERRAFORM_ERROR_PREFIX)
)
Copy link
Contributor

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?

@moelasmar moelasmar added this pull request to the merge queue Sep 14, 2023
Merged via the queue into aws:develop with commit d054a85 Sep 14, 2023
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants