Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent requests on same connection? #95

Closed
basickarl opened this issue Sep 29, 2017 · 4 comments
Closed

Concurrent requests on same connection? #95

basickarl opened this issue Sep 29, 2017 · 4 comments

Comments

@basickarl
Copy link

basickarl commented Sep 29, 2017

I'm running a for loop which invokes 15+ ssh2 connections.

// more code...
const ssh = new SSH({});
await ssh.connect({
        host: host,
        username: user,
        port: port,
        privateKey: key,
    });

I run this 15 times in a for loops quickly, creating concurrent ssh requests (or at least trying to create concurrent requests).

await ssh.execCommand(cmd);

I get the following error on all of the connections except the first one:

{ Error: (SSH) Channel open failure: open failed
    at SSH2Stream.onFailure (/builds/b/e/node_modules/node-ssh/node_modules/ssh2/lib/client.js:1068:13)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at SSH2Stream.emit (events.js:210:7)
    at parsePacket (/builds/b/e/node_modules/ssh2-streams/lib/ssh.js:3423:10)
    at SSH2Stream._transform (/builds/b/e/node_modules/ssh2-streams/lib/ssh.js:551:13)
    at SSH2Stream.Transform._read (_stream_transform.js:190:10)
    at SSH2Stream._read (/builds/b/e/node_modules/ssh2-streams/lib/ssh.js:212:15)
    at SSH2Stream.Transform._write (_stream_transform.js:178:12)
    at doWrite (_stream_writable.js:371:12)
    at writeOrBuffer (_stream_writable.js:357:5)
    at SSH2Stream.Writable.write (_stream_writable.js:274:11)
    at Socket.ondata (_stream_readable.js:626:20)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:250:12) reason: 'CONNECT_FAILED', lang: '' }

This leads me to understand that this package does not support concurrent requests on the same connection? I'm guessing I must open a new connection per request?

@steelbrain
Copy link
Owner

The package does support concurrent connections but there's usually a limit by the server on how much concurrent requests can be run on a connection.

You should not use a for loop to invoke asynchronous methods, you should do them in a pool with a max number or chain-them up or await 1 by 1.

That's just my personal opinion. The error seems to be coming from the base library, you could ask the author why this is happening. My rough guess would be rate limiting on the server side.

@martinlevesque
Copy link

Hey,

I am having the same issue - it crashes the server even if I catch all errors. Will investigate the issue and report it here if I find how to fix it.

@martinlevesque
Copy link

martinlevesque commented Mar 23, 2018

So for me, increasing significantly the MaxSessions in the sshd_config fixed the issue. When you don't set it with OpenSsh, MaxSessions = 10

@steelbrain
Copy link
Owner

Thanks for reporting the fix that worked for you @martinlevesque

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants