darkoperator / darkoperator/Posh-SSH

Invoke-SSHCommand hangs and does not return control to the script when the command hangs on the remote side

Open
#613 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1.1k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

I'm pushing out a 'head' command on some remote files via SSH using Invoke-SSHCommand. Once in a while one or two of these files I'm heading will just hang indefinitely on the command. I can actually reproduce that behavior on those particular files manually and that's not the issue. The issue is that even when Invoke-SSHCommand times out, control never returns to my script and everything hangs indefinitely. In fact, I can't even CTRL-C the script and have to close the session entirely.

Error returned:

Exception calling "EndExecute" with "1" argument(s): "Command 'head -n 10 "/path/to/file"' has timed out."
At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\3.2.4\Posh-SSH.psm1:294 char:25
+                         $Output = $_.cmd.EndExecute($_.Async)
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SshOperationTimeoutException

Wanted to post the issue here before I started trying to muck around in your code in case you have any idea.

Any help is appreciated and also want to add that this is a great module that I get a lot of mileage out of and really appreciate the work.

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Posh-SSH.psm1 around line 294, where Invoke-SSHCommand calls EndExecute after the timeout, and reproduce the behavior with a remote head command that hangs. Trace the timeout and cancellation path; done means the script regains control after the timeout and can be interrupted without closing the session.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.