execCommand throws on large outputs

Open
#474 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript
Domain
backend

Research direction

Start in src/index.ts at the execCommand output collection and final conversion lines linked in the report. Reproduce a command with very large output while using onStdout/onStderr, then run the relevant project checks; done means streaming no longer causes Invalid string length or unnecessary full-output accumulation.

Written by the indexing model from the issue text.

Description

execCommand provides streaming ability via onStdout/onStderr option.
However, even if the option is provided, it still collects the output to own array:
https://github.com/steelbrain/node-ssh/blob/6c57d8f127ab1173cee68de598ff6940575af149/src/index.ts#L394
When the output is very large it fails to convert the array to string:
https://github.com/steelbrain/node-ssh/blob/main/src/index.ts#L423-L424

RangeError: Invalid string length
    at Array.join (<anonymous>)
    at Channel.<anonymous> (redacted/node_modules/node-ssh/lib/esm/index.mjs:302:47)
    at Channel.emit (node:events:526:35)
    at Channel.doClose (redacted\node_modules\ssh2\lib\utils.js:101:21)
    at Object.onceWrapper (node:events:628:28)
    at Channel.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1408:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Besides the error, I think it wastes resources and defeats the purpose of using streams.

Dominant language
TypeScript
Stars
1k
Forks
94
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from steelbrain/node-ssh

All issues in steelbrain/node-ssh

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.