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

Sending SIGTERM to tenv put terraform state at risk #340

Open
nokernel opened this issue Jan 24, 2025 · 5 comments
Open

Sending SIGTERM to tenv put terraform state at risk #340

nokernel opened this issue Jan 24, 2025 · 5 comments
Assignees

Comments

@nokernel
Copy link

nokernel commented Jan 24, 2025

Describe the bug
When using tenv with terraform.

If a user issue one SIGTERM to tenv, tenv send two SIGTERM to terraform without giving time to Terraform to cleanly stop.

Ending up with locked state, and risk of corrupting Terraform state file.

To Reproduce

Set export TENV_DETACHED_PROXY=false because otherwise tenv does not work.

using terraform example

terraform {
  required_version = "1.5.7"
}

resource "terraform_data" "this" {
  provisioner "local-exec" {
    command = "sleep 60"
  }
}
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # terraform_data.this will be created
  + resource "terraform_data" "this" {
      + id = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

terraform_data.this: Creating...
terraform_data.this: Provisioning with 'local-exec'...
terraform_data.this (local-exec): Executing: ["/bin/sh" "-c" "sleep 60"]
^C
Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...

Stopping operation...

Two interrupts received. Exiting immediately. Note that data loss may have occurred.```

Expected behavior
tenv should only send the same amount of SIGTERM received and not two.

Screenshots
See description above

Environment (please complete the following information):

  • OS: MacOS 15.2
  • tofuenv version 4.1.0

Additional context
Add any other context about the problem here.

@dvaumoron
Copy link
Contributor

tenv transmit only the SIGTERM received, however non Windows system, also share it among the process group...

although, I think the simplest fix is to remove the signal transmission on non Windows system...

I will try to do a PR and propose a beta for that soon

@nokernel
Copy link
Author

nokernel commented Jan 27, 2025

Hello,

tenv transmit only the SIGTERM received, however non Windows system, also share it among the process group...

although, I think the simplest fix is to remove the signal transmission on non Windows system...

I will try to do a PR and propose a beta for that soon

Found 2 other issues that are the same I believe see below.

I had to enable TENV_DETACHED_PROXY because the binary would not run on MAC with the ioctl error seems related to this issue #328.

This issue show up when running tenv within pre-commit

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-executables-have-shebangs
      - id: check-merge-conflict
      - id: check-symlinks
      - id: end-of-file-fixer
      - id: no-commit-to-branch
      - id: trailing-whitespace
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.3
    hooks:
      - id: terraform_fmt

Here are the two issues that were closed and are the same "Ctrl-C" double.

#95
#255

Thanks for working on tenv @dvaumoron it is greatly appreciated!

@archoversight
Copy link

Also see #305

@dvaumoron
Copy link
Contributor

Can you test v4.2.0-beta2 ?

@nokernel
Copy link
Author

Can you test v4.2.0-beta2 ?

Hello @dvaumoron worked seems to work for me for this issue.

@dvaumoron dvaumoron self-assigned this Feb 5, 2025
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

No branches or pull requests

3 participants