-
Notifications
You must be signed in to change notification settings - Fork 116
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
Support graceful cancellation #332
Closed
Closed
Conversation
This file contains 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
simon0191
force-pushed
the
ss/graceful-cancellation
branch
5 times, most recently
from
August 31, 2022 13:53
6a4226d
to
59b00d5
Compare
Adjust cmd_default so that it kills the process on context cancellation
simon0191
force-pushed
the
ss/graceful-cancellation
branch
from
August 31, 2022 14:36
59b00d5
to
97168fe
Compare
twmb
added a commit
to redpanda-data/terraform-exec
that referenced
this pull request
Aug 31, 2022
This is an alternative to hashicorp#332, adding an option that enables the user to implement graceful shutdowns for Apply and Destroy operations. Rather than adding an option that changes the behavior of the input context, we instead add an option that specifically sends an interrupt to the terraform process. The input context behavior remains unchanged. This requires the caller to do a bit more orchestration work for timeouts, but keeps context truer to the "abandon work" intent. This also allows users to force quit _even if_ they are in the middle of a graceful shutdown, rathern than having one behavior mutually exclusive with the other.
twmb
added a commit
to redpanda-data/terraform-exec
that referenced
this pull request
Aug 31, 2022
This is an alternative to hashicorp#332, adding an option that enables the user to implement graceful shutdowns for Apply and Destroy operations. Rather than adding an option that changes the behavior of the input context, we instead add an option that specifically sends an interrupt to the terraform process. The input context behavior remains unchanged. This requires the caller to do a bit more orchestration work for timeouts, but keeps context truer to the "abandon work" intent. This also allows users to force quit _even if_ they are in the middle of a graceful shutdown, rathern than having one behavior mutually exclusive with the other.
twmb
added a commit
to redpanda-data/terraform-exec
that referenced
this pull request
Aug 31, 2022
This is an alternative to hashicorp#332, adding an option that enables the user to implement graceful shutdowns for Apply and Destroy operations. Rather than adding an option that changes the behavior of the input context, we instead add an option that specifically sends an interrupt to the terraform process. The input context behavior remains unchanged. This requires the caller to do a bit more orchestration work for timeouts, but keeps context truer to the "abandon work" intent. This also allows users to force quit _even if_ they are in the middle of a graceful shutdown, rathern than having one behavior mutually exclusive with the other.
Closing in favor of #334 which is a much simpler and nicer implementation |
twmb
added a commit
to redpanda-data/terraform-exec
that referenced
this pull request
Sep 1, 2022
This is an alternative to hashicorp#332, adding an option that enables the user to implement graceful shutdowns for Apply and Destroy operations. Rather than adding an option that changes the behavior of the input context, we instead add an option that specifically sends an interrupt to the terraform process. The input context behavior remains unchanged. This requires the caller to do a bit more orchestration work for timeouts, but keeps context truer to the "abandon work" intent. This also allows users to force quit _even if_ they are in the middle of a graceful shutdown, rathern than having one behavior mutually exclusive with the other.
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.
This PR adds support for graceful cancellation and a
GracefulShutdownTimeout
option for apply and destroy commands.Currently when the context is cancelled a SIGKILL is sent to Terraform. This is the default behaviour of
exec.CommandContext
. The SIGKILL forcefully kills the Terraform process and therefore it doesn’t start a graceful shutdown which sometimes ends up with the state lock not being released.The proposed fix is that on context cancellation, a SIGINT is sent so that Terraform starts a graceful shutdown with the hope of releasing the lock and allowing providers to gracefully terminate, and then, after
GracefulShutdownTimeout
if the command hasn’t finished, then a SIGKILL is sent to forcefully terminate the process.When a command is started, the command that is created is run without a context (equivalent to passing
context.Background()
), and in a concurrent go routine the cancellation of the parent context is monitored.When the parent context is cancelled, a SIGINT is sent to the command. After
GracefulShutdownTimeout
passes, if the command hasn't finished, a SIGKILL is sent to the command to forcefully kill it.The
GracefulShutdownTimeout
is also useful so that the caller of tf-exec is able to configure for how long it's willing to wait for the cancellation, which depends on how each provider handles cancellations.Refs