High memory allocation using SshCommand
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 993
- Avg merge
- 9d 21h
- Merged PRs (30d)
- 1
Description
Hi,
I noticed using SSH.Net there are a few issues using SshCommand:
- Allocation of 2kB of buffer for every command, even short ones without output and without monitoring output
- Not reading output causes these buffers to grow indefinitely for long running commands
- No way to discard this output easily
- Using sshcommands many at a time in a pool causes huge GC pressure with the many large allocations
An example from a single command running without cleaning the streams shows it allocating over 300kB of memory in a VS snapshot.
Possible solutions:
- Allocate the pipestreams only when accessed, discarding input otherwise (breaking change)
- Creating a new sshcommand that does not allocate.
I will be creating a pull request for scenario 2 as i need a solution for a project asap.
Thanks for the library!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SshCommand implementation and inspect how its output streams are allocated and consumed, using the reported memory snapshot as the baseline. Determine which behavior should change for commands whose output is not monitored, then verify that long-running commands no longer retain unbounded output and that the intended scenario is covered by tests.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100