sshnet / sshnet/SSH.NET

SshClient - thread gets blocked indefinitely, lock not released

Open
#755 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

Using version 2020.0.0-beta1 SshClient, I was doing some load testing, and consistently encountered an issue when executing commands for an extended period of time using a single client instance (a few hours running around 1M commands).

When running the SshCommand.Execute() method, the method SemaphoreLight.Wait() waits for a lock to be released indefinitely. (SemaphoreLight.cs : Line 110)

Call stack:
System.Private.CoreLib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext)
Renci.SshNet.dll!Renci.SshNet.Common.SemaphoreLight.Wait()
Renci.SshNet.dll!Renci.SshNet.Channels.ChannelSession.SendChannelOpenMessage()
Renci.SshNet.dll!Renci.SshNet.Channels.ChannelSession.Open()
Renci.SshNet.dll!Renci.SshNet.SshCommand.BeginExecute(System.AsyncCallback callback, object state)

As a workaround, disposing and recreating the SshClient object after every 10000 executions solved the problem.

Contributor guide

Open the contributing guide

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 with SshCommand.Execute and its BeginExecute call path, then inspect ChannelSession.Open and SemaphoreLight.cs around line 110. Reproduce the long-running load test described in the issue using one SshClient and observe where the wait remains blocked. Done means extended command execution no longer leaves the client waiting indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
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.