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

[RFE] Handle SIGINT and interrupt command execution #5

Closed
blanquicet opened this issue Feb 16, 2022 · 3 comments · Fixed by #44
Closed

[RFE] Handle SIGINT and interrupt command execution #5

blanquicet opened this issue Feb 16, 2022 · 3 comments · Fixed by #44
Assignees
Labels
enhancement New feature or request run-command Command run-command
Milestone

Comments

@blanquicet
Copy link
Member

blanquicet commented Feb 16, 2022

Current situation

The SIGINT signal is not managed at all.

Impact

Users need to wait until that previous command execution finishes before being able to run another command:

$ ./kubectl-az run-command "ip route" --node aks-agentpool-38928455-vmss000000 -v
Command: ip route shfdsafddow
Virtual Machine Scale Set VM: {
  "SubscriptionID": "fa899caf-8f31-4531-a2c5-4e23e4bbcd0d",
  "NodeResourceGroup": "mc_mauricio-kubeaz-test_mauricio-kubeaz-test_eastus",
  "VMScaleSet": "aks-agentpool-38928455-vmss",
  "InstanceID": "0"
}

Running...
^C
$ ./kubectl-az run-command "ip route" --node aks-agentpool-38928455-vmss000000 -v
Command: ip route shfdsafddow
Virtual Machine Scale Set VM: {
  "SubscriptionID": "fa899caf-8f31-4531-a2c5-4e23e4bbcd0d",
  "NodeResourceGroup": "mc_mauricio-kubeaz-test_mauricio-kubeaz-test_eastus",
  "VMScaleSet": "aks-agentpool-38928455-vmss",
  "InstanceID": "0"
}

Error: failed to run command: couldn't run command: POST https://management.azure.com/subscriptions/fa899caf-8f31-4531-a2c5-4e23e4bbcd0d/resourceGroups/mc_mauricio-kubeaz-test_mauricio-kubeaz-test_eastus/providers/Microsoft.Compute/virtualMachineScaleSets/aks-agentpool-38928455-vmss/virtualmachines/0/runCommand
--------------------------------------------------------------------------------
RESPONSE 409: 409 Conflict
ERROR CODE: Conflict
--------------------------------------------------------------------------------
{
  "error": {
    "code": "Conflict",
    "message": "Run command extension execution is in progress. Please wait for completion before invoking a run command."
  }
}
--------------------------------------------------------------------------------

Ideal future situation

Handle SIGINT and interrupt command execution

Implementation options

According to the documentation, we can't cancel a running script. However, BeginRunCommand receives a context, maybe there is something we can do with it.

@mqasimsarfraz
Copy link
Member

I did initial investigation regarding passing a cancelable context to BeginRunCommand and it seems it doesn't help with cancelling the actual run command and only effects the polling:

Error: failed to run command: error polling command response: context deadline exceeded

I will investigate if there is still an option to avoid conflicts when re-running the command.

@blanquicet blanquicet added this to the v0.1.1 milestone Apr 5, 2023
@blanquicet
Copy link
Member Author

blanquicet commented Apr 5, 2023

I just realize that maybe we won't be able to do too much on this issue after re-reading the documentation:

You can't cancel a running script.

Maybe, what we can do is to handle this kind of signals and improve the UX:

$ kubectl az run-command "ip route" --node aks-agentpool-12345678-vmss000000
Running...
^C
Warn: The requested command hasn't finished yet...
Warn: Hit Ctrl+C again to exit, but please notice the command will continue running in the node anyway, and you will be unable to see the output or run another command until it finishes.
^C
Exiting...
$ 

@mqasimsarfraz
Copy link
Member

I agree. I think having a warning like this can be useful so users are aware of the consequence of cancellation an unfinished command. Also, I am thinking of wrapping the run-command in timeout and set the default value to 300 seconds . Let me have a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request run-command Command run-command
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants