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.
- package/lib/sshExec.js +29 -27
- 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
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
try {
|
|
283
|
+
if (await existsMaster(hostInfo)) {
|
|
284
|
+
const args = getSshOption(hostInfo);
|
|
285
|
+
args.push("-Oexit");
|
|
284
286
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
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
|
|