az vm run-command create doesn't return even the script is finished
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
### Describe the bug
I'm running PowerShell scripts on Windows VMs with `az vm run-command create ...` command as part of our DevOps pipelines. I'm running those on multiple similar VMs but the command doesn't return randomly on many VMs even though the script has finished on VM. I'm logging the execution and PowerShell script does call `exit 0` as last step but still the run-command hangs for some reason and eventually times out in DevOps. I can see with `az vm run-command show ...` that command is still in
`"executionState": "Running"` and `"provisioningState": "Creating"` states.
### Related command
```
az vm run-command create \
--name MyScript \
--vm-name vm-server1 \
--resource-group rg-myservers \
--run-as-user mylocaluser \
--run-as-password \
--script "PowerShell -ExecutionPolicy Unrestricted -NonInteractive -File C:\temp\myscript.ps1 -Foo:Bar"
```
### Errors
I don't get errors but the command hangs for over an hour.
I can see the status with separate command:
```bash
az vm run-command show --name MyScript --resource-group rg-myservers --vm-name vm-server1 --expand instanceView
```
```
{
"asyncExecution": false,
"errorBlobUri": null,
"id": "/subscriptions/.../resourceGroups/rg-myservers/providers/Microsoft.Compute/virtualMachines/vm-server1/runCommands/MyScript",
"instanceView": {
"endTime": null,
"error": null,
"executionMessage": null,
"executionState": "Running",
"exitCode": 0,
"output": "...Script finished. Exiting the script.",
"startTime": "2024-01-11T06:56:23.575284+00:00",
"statuses": null
},
"location": "westeurope",
"name": "MyScript",
"outputBlobUri": null,
"parameters": null,
"protectedParameters": null,
"provisioningState": "Creating",
"resourceGroup": "rg-myservers",
"runAsPassword": null,
"runAsUser": "mylocaluser",
"source": {
"commandId": null,
"script": "PowerShell -ExecutionPolicy Unrestricted -NonInteractive -File C:\\temp\\myscript.ps1 -Foo:Bar",
"scriptUri": null
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/runCommands"
}
```
### Issue script & Debug output
-
### Expected behavior
I would expect the `az vm run-command create ...` to return quite quickly after the given script is completed.
### Environment Summary
```
azure-cli 2.55.0 *
core 2.55.0 *
telemetry 1.1.0
Extensions:
account 0.2.5
authV2 0.1.1
azure-devops 0.25.0
```
### Additional context
I'm not able to delete the command either so it will block our DevOps pipelines for over an hour before command can be run again. I have also tried to delete the command but that also might take an hour to complete. For example:
```
> az vm run-command delete --name MyScript --resourcegroup rg-myservers --vm-name vm-server1 --yes --verbose
Command ran in 2950.874 seconds (init: 0.437, invoke: 2950.437)
```
Contributor guide
Assessment
This issue has not been assessed yet.