Skip to content

SSH connection hangs when session is unexpectedly terminated #26228

@dmjoker

Description

@dmjoker

Prerequisites

Steps to reproduce

An SSH connection hangs when the session is unexpectedly terminated. For example, if you connect to a remote Linux or Mac OS X machine and execute the 'sudo reboot' command (or otherwise disrupt SSH or the computer), the connection will hang with the message 'Connection to computername.domainname.com closed by remote host.' After this point, no further PowerShell commands will work. Ctrl+C also doesn't help in this situation.

$s = new-PSSession -HostName 'testcomputername.dom.com' -Options @{ StrictHostKeyChecking = 'no'; UserKnownHostsFile = '\\.\NUL'} -UserName 'username' -ConnectingTimeout 5000
Invoke-Command -Session $s -ScriptBlock {get-host; Start-Sleep -Seconds 1; sudo reboot

Expected behavior

Connection error and stop cmdlet

Actual behavior

Hanging

Error details

Not error, just hanging.

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.3
PSEdition                      Core
GitCommitId                    7.5.3
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


The problem also occurs on older versions.

Visuals

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.WG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions