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

Wait-Job behavior with timeout #10501

Open
kaisxu opened this issue Sep 9, 2019 · 3 comments
Open

Wait-Job behavior with timeout #10501

kaisxu opened this issue Sep 9, 2019 · 3 comments
Labels
Issue-Bug Issue has been identified as a bug in the product WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Comments

@kaisxu
Copy link

kaisxu commented Sep 9, 2019

Steps to reproduce

The code is aim to set time timeout for back ground jobs. I removed unrelated code here. The behavior is strange for me. Here is the code.

function JobWithTimeout {
    param(
        [System.Management.Automation.Job]
        [parameter(
            Mandatory = $true,
            ValueFromPipeline = $true)]
        [ValidateNotNull()]
        $Job,

        [parameter(Mandatory = $true)]
        [ValidateNotNull()]
        [int]
        $TimeoutInSec
    )
    
    Process {
        $Job | Wait-Job -Timeout $TimeoutInSec
        if ($(Get-Job -Id $Job.Id).State -eq "Running") {
            Write-Warning "Job timeout."
        }

        $Job| Stop-Job
        $Job| Receive-Job
        $Job| Remove-Job
    }
}

Start-Job -ScriptBlock {
    Write-Warning "res"
    $aaaa = 1   # <-- remove this line cause timeout
} | JobWithTimeout -Timeout 10

Expected behavior

Always get "WARNING: res"

Actual behavior

This code works fine and get result “Warning: res”. But if I remove L30, which is meaningless, the job always timeout while Wait-Job. Is this a expected behavior? Could you explain the underlying mechanisms to me?
image

Environment data

Tested on both Windows Powershell and Powershell Core
image
image

@kaisxu kaisxu added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Sep 9, 2019
@iSazonov
Copy link
Collaborator

Please check on latest PowerShell 7 Preview build.

@kaisxu
Copy link
Author

kaisxu commented Sep 10, 2019

Same issue on 7.0.0-preview3

PS D:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.3
PSEdition                      Core
GitCommitId                    7.0.0-preview.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@iSazonov iSazonov added the WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module label Sep 10, 2019
@iSazonov iSazonov added Issue-Bug Issue has been identified as a bug in the product and removed Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a labels Jan 15, 2021
@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
@kaisxu
Copy link
Author

kaisxu commented Nov 16, 2023

Still repro in PowerShell 7.3.9, same script

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module
Projects
None yet
Development

No branches or pull requests

2 participants