-
-
Notifications
You must be signed in to change notification settings - Fork 130
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(vm): better handle of ctrl+c when qemu is not responding #627
Conversation
07306a5
to
ffc6689
Compare
…u agent lookups would fail Signed-off-by: TheNotary <799247+TheNotary@users.noreply.github.com>
ffc6689
to
4754c35
Compare
Thanks, it makes the code look more readable. Improving the behavior on Ctrl-C with Proxmox-enabled yet VM-missing qemu-guest-agent would be nice. Current behavior:
Tried the PR, the behavior seems the same (tested on Terraform v1.5.3, newer versions may differ...) Tried modifying it to checking
That gave me an idea for the following modification: ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
for timeElapsed.Seconds() < timeMaxSeconds {
timeElapsed = time.Since(timeStart)
// check if terraform wants to shut us down (we try to poll the ctx every 200ms)
if ctx.Err() != nil {
return nil, fmt.Errorf("error waiting for VM network interfaces: %w", ctx.Err())
}
select {
case <-ch:
{
return nil, fmt.Errorf("error by signal")
}
default:
}
....
Getting signal directly instead of using contex seems like an ugly hack, but I no idea if there even is a non-hacky solution. |
13fb870
to
4754c35
Compare
Didn't notice this until just now. First thanks for the code quality feedback! About the difference in behavior between If your sigint check does the trick, I say go for it. I'm getting the impression, Hashicorp didn't spend a lot of time what to do when a user I accidentally clicked the update branch but I pushed it back to how it was where I left off. It looks like you're using a case/switch that looks more elegant. If you'd like to own this fix from here, I'd appreciate it. I'm away from my infrastructure at the moment so it would be difficult for me to do testing until I'm done traveling. |
It looks like the new linter started complaining about some older code not related to this PR. #645 should fix it, so please merge / rebase on |
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
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 the PR, @TheNotary!
I feel like most of those "sleep & loop" waiting patterns can be updated to something more elegant, there are bunch of libraries around that can handle waiting, with different type of strategies, better error handling, etc, etc., but even this improvement is great!
I've incorporated @otopetrik 's suggestion and tested in my env, everything seems to be working as expected, so
LGTM! 🚀
Contributor's Note
/docs
for any user-facing features or additions./example
for any new or updated resources / data sources.make example
to verify that the change works as expected.I'm still getting up to speed with GoLang, and I'm finding it very tricky to know whether my code is readable or not. Usually this type of refactor shortens the code up, but in this case it got longer so I'm reluctant raising this PR. (Was the deep nesting intentional to shorten the code?)
I had a hunch that using a golang
tick
pattern here might help, but I thought I'd just check in and see what others thought before racking my brain further. If someone wants to pick up this PR and finish the refactor, that would be great, it's been really slow going for me and I might learn faster just seeing the end form.Proof of Work
To reproduce the results, in terraform, configure a VM to
agent.enabled = true
but then in the VM you're testing against, just delete the qemu-guest-agent and reboot. Thereafter, aterraform plan
operation will likely hang, and ctrl + C will be unable to exit from the provider's operation because of the structure of the loop and the use ofcontinue
statements.Below is a screenshot of this patch allowing ctrl + c to be captured.
Community Note