ssh-client-wrapper 3.4.6 → 3.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/sshExec.js +32 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -206,6 +206,8 @@ Checks if a connection to the remote host can be established.
|
|
|
206
206
|
|
|
207
207
|
### Connection failures
|
|
208
208
|
|
|
209
|
+
Calls made at the same time with one wrapper object share the master connection which is being made, so ssh logs in once and all of them get the same result (the `timeout` of the first call applies).
|
|
210
|
+
|
|
209
211
|
If the login can not be done, the promise is rejected with an `Error` as soon as `ssh` gives up. `err.code` tells the cause, and `err.output` has what `ssh` said (the last 4096 characters). `host`, `user` and `port` tell which login failed.
|
|
210
212
|
|
|
211
213
|
| `err.code` | cause |
|
|
@@ -219,6 +221,7 @@ If the login can not be done, the promise is rejected with an `Error` as soon as
|
|
|
219
221
|
| `BAD_PORT` | invalid port number |
|
|
220
222
|
| `CONTROL_SOCKET_FAILED` | the socket of the master connection can not be created |
|
|
221
223
|
| `TIMEEXPIRE` | `ssh` did not finish within `timeout` |
|
|
224
|
+
| `PTY_EXITED` | the shell which starts the master connection ended before the login succeeded (e.g. `disconnect()` was called meanwhile) |
|
|
222
225
|
| `SSH_FAILED` | any other failure; `message` is the last line which `ssh` said |
|
|
223
226
|
|
|
224
227
|
### Wrong password
|
package/lib/sshExec.js
CHANGED
|
@@ -196,6 +196,9 @@ async function verifyConnection(hostInfo, timeout) {
|
|
|
196
196
|
hostInfo._connectionVerified = true;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
//master connections which are being made, per hostInfo object
|
|
200
|
+
const connectingMasters = new WeakMap();
|
|
201
|
+
|
|
199
202
|
/**
|
|
200
203
|
* create master ssh connection
|
|
201
204
|
* if the master connection is not used, only check that the host can be logged in to
|
|
@@ -224,6 +227,24 @@ export async function connect(hostInfo, timeout = 60) {
|
|
|
224
227
|
return verifyConnection(hostInfo, timeout);
|
|
225
228
|
}
|
|
226
229
|
|
|
230
|
+
//calls made at the same time for one hostInfo share the connection which is being made (with the timeout of the first one).
|
|
231
|
+
//Otherwise each of them would replace the master pty of the one before
|
|
232
|
+
let connecting = connectingMasters.get(hostInfo);
|
|
233
|
+
if (!connecting) {
|
|
234
|
+
connecting = connectMaster(hostInfo, timeout).finally(()=>{
|
|
235
|
+
connectingMasters.delete(hostInfo);
|
|
236
|
+
});
|
|
237
|
+
connectingMasters.set(hostInfo, connecting);
|
|
238
|
+
}
|
|
239
|
+
return connecting;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* create the master connection unless there is one
|
|
244
|
+
* @param {object} hostInfo - hostinfo object
|
|
245
|
+
* @param {number} timeout - timeout (in sec.)
|
|
246
|
+
*/
|
|
247
|
+
async function connectMaster(hostInfo, timeout) {
|
|
227
248
|
if (await existsMaster(hostInfo, timeout)) {
|
|
228
249
|
debugVerbose("master connection exists");
|
|
229
250
|
return;
|
|
@@ -300,9 +321,19 @@ export async function connect(hostInfo, timeout = 60) {
|
|
|
300
321
|
sshLoginCallback(output, pty, hostInfo.password, hostInfo.passphrase, debugSendMasterPty)
|
|
301
322
|
.catch(reject);
|
|
302
323
|
});
|
|
324
|
+
//the shell never exits by itself. It has been killed, e.g. by disconnect(), or it has crashed
|
|
303
325
|
pty.onExit((e)=>{
|
|
304
326
|
debug("master pty exit", e);
|
|
305
|
-
|
|
327
|
+
if (output.includes(okMark)) {
|
|
328
|
+
resolve();
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const err = failure();
|
|
332
|
+
if (!output.includes(failMark)) {
|
|
333
|
+
err.message = "the shell of the master connection has exited before the login succeeded";
|
|
334
|
+
err.code = "PTY_EXITED";
|
|
335
|
+
}
|
|
336
|
+
reject(err);
|
|
306
337
|
});
|
|
307
338
|
});
|
|
308
339
|
|