ssh-client-wrapper 3.1.3 → 3.1.4

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.
Files changed (2) hide show
  1. package/lib/sshExec.js +29 -27
  2. package/package.json +1 -1
package/lib/sshExec.js CHANGED
@@ -138,7 +138,8 @@ async function existsMaster(hostInfo, argTimeout) {
138
138
  }
139
139
  }
140
140
 
141
- return !/Control socket connect.*: No such file or directory/.test(output);
141
+ //"Connection refused" means that the socket is left but nobody listens (the master was killed, or it is exiting)
142
+ return !/Control socket connect.*: (No such file or directory|Connection refused)/.test(output);
142
143
  }
143
144
 
144
145
  /**
@@ -278,35 +279,36 @@ export async function connect(hostInfo, timeout = 60) {
278
279
  export async function disconnect(hostInfo) {
279
280
  debug("disconnect called");
280
281
 
281
- if (await existsMaster(hostInfo)) {
282
- const args = getSshOption(hostInfo);
283
- args.push("-Oexit");
282
+ try {
283
+ if (await existsMaster(hostInfo)) {
284
+ const args = getSshOption(hostInfo);
285
+ args.push("-Oexit");
284
286
 
285
- let output = "";
286
- const cb = (e)=>{
287
- output += e;
288
- };
289
- try {
290
- debug(`disconnect: ${sshCmd} ${args.join(" ")}`);
291
- await fork(hostInfo, sshCmd, args, 0, cb);
292
- } catch (err) {
293
- if (err.rt === 255) {
294
- return;
295
- }
296
- if (/Control socket connect.*: No such file or directory/.test(output)) {
297
- return;
287
+ let output = "";
288
+ const cb = (e)=>{
289
+ output += e;
290
+ };
291
+ try {
292
+ debug(`disconnect: ${sshCmd} ${args.join(" ")}`);
293
+ await fork(hostInfo, sshCmd, args, 0, cb);
294
+ debug(`disconnected from ${hostInfo.host}`);
295
+ } catch (err) {
296
+ //the master is already gone
297
+ const gone = err.rt === 255 || /Control socket connect.*: No such file or directory/.test(output);
298
+ if (!gone) {
299
+ throw err;
300
+ }
298
301
  }
299
- throw err;
302
+ } else {
303
+ debug(`disconnect: master session to ${hostInfo.host} does not exist`);
304
+ }
305
+ } finally {
306
+ //the pty must be released even if the master is already gone. It keeps the process alive.
307
+ if (hostInfo.masterPty) {
308
+ debug("exit masterPty");
309
+ sendPty(hostInfo.masterPty, "exit \n", debugSendMasterPty, 228);
310
+ hostInfo.masterPty = null;
300
311
  }
301
- debug(`disconnected from ${hostInfo.host}`);
302
- } else {
303
- debug(`disconnect: master session to ${hostInfo.host} does not exist`);
304
- }
305
-
306
- if (hostInfo.masterPty) {
307
- debug("exit masterPty");
308
- sendPty(hostInfo.masterPty, "exit \n", debugSendMasterPty, 228);
309
- hostInfo.masterPty = null;
310
312
  }
311
313
  }
312
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "keywords": [
6
6
  "ssh",