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

Fixed websocket related tasks in InvokeAzContainerInstanceCommand_ExecuteExpanded.cs #22486

Conversation

andreygoran
Copy link
Contributor

@andreygoran andreygoran commented Aug 3, 2023

Description

This PR fixes the problem with Invoke-AzContainerInstanceCommand not returning any result when it's run under certain conditions, and closes #22453

The problem occurres when powershell is launched with redirection of input stream (and apparently this is how it's being run in Azure ARM Powershell Deployment Scripts and in Azure Powershell Functions).

Test.ps1 code used to reproduce the problem:

$HostName = Invoke-AzContainerInstanceCommand -ContainerGroupName mypowershellapp -ContainerName mypowershellapp -ResourceGroupName MyResourceGroup -PassThru -Command 'hostname'
("Host: " + $HostName) | Out-Host

Results before the fix:

$ pwsh Test.ps1
SandboxHost-638266427706169802
Host: SandboxHost-638266427706169802
$ echo | pwsh Test.ps1
Host: 

Results after the fix:

$ pwsh Test.ps1
SandboxHost-638266427706169802
Host: SandboxHost-638266427706169802
$ echo | pwsh Test.ps1
SandboxHost-638266427706169802
Host: SandboxHost-638266427706169802

Related Issues

Fixed: #22453
Probably related: #19247
Probably related: #15754 (comment)

Root Cause Analysis

The root cause of the bug was using a return Task.Factory.StartNew(async () => {...}) construction to handle working with websockets doing actual communication with container instance. This code pattern is dangerous and should not be used, see for details https://blog.stephencleary.com/2013/08/startnew-is-dangerous.html

Another problem was using Console.KeyAvailable which throws an exception when input redirection is used. This was fixed by adding Console.IsInputRedirected validation.

Checklist

  • SHOULD select appropriate branch. Cmdlets from Autorest.PowerShell should go to generation branch.
  • SHOULD make the title of PR clear and informative, and in the present imperative tense.
  • SHOULD update ChangeLog.md file(s) appropriately
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense. Add changelog in description section if PR goes into generation branch.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD have approved design review for the changes in this repository (Microsoft internal only) with following situations
    • Create new module from scratch
    • Create new resource types which are not easy to conform to Azure PowerShell Design Guidelines
    • Create new resource type which name doesn't use module name as prefix
    • Have design question before implementation
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT introduce breaking changes in Az minor release except preview version.
  • SHOULD NOT adjust version of module manually in pull request

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Aug 3, 2023

️✔️Az.Accounts
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Az.ContainerInstance
️✔️Build
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Breaking Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
⚠️Signature Check
⚠️PowerShell Core - Windows
Type Cmdlet Description Remediation
⚠️ Get-AzContainerGroup Get-AzContainerGroup Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerGroup Get-AzContainerGroup changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceCachedImage Get-AzContainerInstanceCachedImage Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceCachedImage Get-AzContainerInstanceCachedImage changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceCapability Get-AzContainerInstanceCapability Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceCapability Get-AzContainerInstanceCapability changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceLog Get-AzContainerInstanceLog Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceLog Get-AzContainerInstanceLog changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceUsage Get-AzContainerInstanceUsage Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceUsage Get-AzContainerInstanceUsage changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupImageRegistryCredentialObject New-AzContainerGroupImageRegistryCredentialObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupImageRegistryCredentialObject New-AzContainerGroupImageRegistryCredentialObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupPortObject New-AzContainerGroupPortObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupPortObject New-AzContainerGroupPortObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupVolumeObject New-AzContainerGroupVolumeObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupVolumeObject New-AzContainerGroupVolumeObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceEnvironmentVariableObject New-AzContainerInstanceEnvironmentVariableObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceEnvironmentVariableObject New-AzContainerInstanceEnvironmentVariableObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceHttpHeaderObject New-AzContainerInstanceHttpHeaderObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceHttpHeaderObject New-AzContainerInstanceHttpHeaderObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceInitDefinitionObject New-AzContainerInstanceInitDefinitionObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceInitDefinitionObject New-AzContainerInstanceInitDefinitionObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceObject New-AzContainerInstanceObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceObject New-AzContainerInstanceObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstancePortObject New-AzContainerInstancePortObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstancePortObject New-AzContainerInstancePortObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceVolumeMountObject New-AzContainerInstanceVolumeMountObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceVolumeMountObject New-AzContainerInstanceVolumeMountObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️Windows PowerShell - Windows
Type Cmdlet Description Remediation
⚠️ Get-AzContainerGroup Get-AzContainerGroup Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerGroup Get-AzContainerGroup changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceCachedImage Get-AzContainerInstanceCachedImage Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceCachedImage Get-AzContainerInstanceCachedImage changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceCapability Get-AzContainerInstanceCapability Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceCapability Get-AzContainerInstanceCapability changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint Get-AzContainerInstanceContainerGroupOutboundNetworkDependencyEndpoint changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceLog Get-AzContainerInstanceLog Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceLog Get-AzContainerInstanceLog changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ Get-AzContainerInstanceUsage Get-AzContainerInstanceUsage Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ Get-AzContainerInstanceUsage Get-AzContainerInstanceUsage changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupImageRegistryCredentialObject New-AzContainerGroupImageRegistryCredentialObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupImageRegistryCredentialObject New-AzContainerGroupImageRegistryCredentialObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupPortObject New-AzContainerGroupPortObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupPortObject New-AzContainerGroupPortObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerGroupVolumeObject New-AzContainerGroupVolumeObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerGroupVolumeObject New-AzContainerGroupVolumeObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceEnvironmentVariableObject New-AzContainerInstanceEnvironmentVariableObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceEnvironmentVariableObject New-AzContainerInstanceEnvironmentVariableObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceHttpHeaderObject New-AzContainerInstanceHttpHeaderObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceHttpHeaderObject New-AzContainerInstanceHttpHeaderObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceInitDefinitionObject New-AzContainerInstanceInitDefinitionObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceInitDefinitionObject New-AzContainerInstanceInitDefinitionObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceObject New-AzContainerInstanceObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceObject New-AzContainerInstanceObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstancePortObject New-AzContainerInstancePortObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstancePortObject New-AzContainerInstancePortObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
⚠️ New-AzContainerInstanceVolumeMountObject New-AzContainerInstanceVolumeMountObject Changes the ConfirmImpact but does not set the SupportsShouldProcess property to true in the cmdlet attribute. Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue
⚠️ New-AzContainerInstanceVolumeMountObject New-AzContainerInstanceVolumeMountObject changes the confirm impact. Please ensure that the change in ConfirmImpact is justified Verify that ConfirmImpact is changed appropriately by the cmdlet. It is very rare for a cmdlet to change the ConfirmImpact.
️✔️Help File Existence Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️File Change Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️UX Metadata Check
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows
️✔️Test
️✔️PowerShell Core - Linux
️✔️PowerShell Core - MacOS
️✔️PowerShell Core - Windows
️✔️Windows PowerShell - Windows

@ghost ghost added the customer-reported label Aug 3, 2023
@ghost
Copy link

ghost commented Aug 3, 2023

Thank you for your contribution andreygoran! We will review the pull request and get back to you soon.

@andreygoran
Copy link
Contributor Author

@andreygoran please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@YanaXu
Copy link
Contributor

YanaXu commented Aug 4, 2023

Hi @andreygoran , If you are from Microsoft, please join your github account to Azure org.

@YanaXu YanaXu self-assigned this Aug 4, 2023
@andreygoran
Copy link
Contributor Author

Hi @andreygoran , If you are from Microsoft, please join your github account to Azure org.

I'm not from Microsoft.

@YanaXu YanaXu assigned BethanyZhou and unassigned YanaXu Aug 4, 2023
@BethanyZhou
Copy link
Contributor

Thanks for your contribution! As Az.ContainerInstance is a generated module, please target your PR to generation branch. I'm checking these points and will go back to you soon.

@andreygoran andreygoran changed the base branch from main to generation August 7, 2023 11:16
@andreygoran andreygoran changed the base branch from generation to main August 7, 2023 11:17
@andreygoran
Copy link
Contributor Author

Thanks for your contribution! As Az.ContainerInstance is a generated module, please target your PR to generation branch. I'm checking these points and will go back to you soon.

@BethanyZhou I added another PR #22515
It's basically the same fixes, but without src/ContainerInstance/ChangeLog.md (it's not part of generation branch)

@BethanyZhou
Copy link
Contributor

Close as tracked by #22515

@BethanyZhou BethanyZhou closed this Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invoke-AzContainerInstanceCommand -PassThru returns nothing when called from ARM deployment script
3 participants