ssh-client-wrapper 2.0.1 → 2.0.2
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/.github/workflows/coverage_report.yml +2 -0
- package/lib/fork.js +3 -1
- package/lib/sshExec.js +23 -17
- package/package.json +1 -1
package/lib/fork.js
CHANGED
|
@@ -75,7 +75,9 @@ async function fork(hostInfo, cmd, args, timeout, outputCallback) {
|
|
|
75
75
|
if (timeout > 0) {
|
|
76
76
|
ac = watchDogTimer(timeout, cmd, ()=>{
|
|
77
77
|
ptyProcess.kill();
|
|
78
|
-
|
|
78
|
+
const err = new Error(`watchdog timer expired ${timeout}`);
|
|
79
|
+
err.code = "TIMEEXPIRE";
|
|
80
|
+
reject(err);
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
ptyProcess.onData(buff2String.bind(null, debugVerbose));
|
package/lib/sshExec.js
CHANGED
|
@@ -64,7 +64,7 @@ async function canConnect(hostInfo, timeout = 60) {
|
|
|
64
64
|
* @param {Object} hostInfo - hostinfo object
|
|
65
65
|
* @returns {boolean} - true if master session exists
|
|
66
66
|
*/
|
|
67
|
-
async function existsMaster(hostInfo) {
|
|
67
|
+
async function existsMaster(hostInfo, argTimeout) {
|
|
68
68
|
debugVerbose("existsMaster called");
|
|
69
69
|
const args = getSshOption(hostInfo);
|
|
70
70
|
args.push("-Ocheck");
|
|
@@ -74,20 +74,22 @@ async function existsMaster(hostInfo) {
|
|
|
74
74
|
output += e;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const
|
|
78
|
-
const timeout = hostInfo.ConnectTimeout || 60;
|
|
77
|
+
const timeout = argTimeout || hostInfo.ConnectTimeout || 60;
|
|
79
78
|
debug(`check master session: ${sshCmd} ${args.join(" ")}`);
|
|
80
79
|
|
|
81
80
|
try {
|
|
82
81
|
await fork(hostInfo, sshCmd, args, timeout, cb);
|
|
83
82
|
} catch (err) {
|
|
83
|
+
if (err.code === "TIMEEXPIRE") {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
84
86
|
if (err.rt !== 255) {
|
|
85
87
|
debug("check master session failed", err);
|
|
86
88
|
throw err;
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
return
|
|
92
|
+
return !/Control socket connect.*: No such file or directory/.test(output);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
@@ -95,7 +97,7 @@ async function existsMaster(hostInfo) {
|
|
|
95
97
|
* @param {Object} hostInfo - hostinfo object
|
|
96
98
|
*/
|
|
97
99
|
async function connect(hostInfo, timeout = 60) {
|
|
98
|
-
if (await existsMaster(hostInfo)) {
|
|
100
|
+
if (await existsMaster(hostInfo, timeout)) {
|
|
99
101
|
debugVerbose("master connection exists");
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
@@ -105,20 +107,22 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
105
107
|
|
|
106
108
|
debug(`create master ssh session to ${hostInfo.host}`);
|
|
107
109
|
|
|
108
|
-
const ac = watchDogTimer(timeout, "make connection", ()=>{
|
|
109
|
-
sendPty(hostInfo.masterPty, "\n", debugSendMasterPty, 137);
|
|
110
|
-
sendPty(hostInfo.masterPty, "exit\n", debugSendMasterPty, 138);
|
|
111
|
-
|
|
112
|
-
const err = new Error(`can not connect within ${timeout} sec`);
|
|
113
|
-
err.host = hostInfo.host;
|
|
114
|
-
err.user = hostInfo.user;
|
|
115
|
-
err.port = hostInfo.port;
|
|
116
|
-
throw err;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
110
|
const words = crypto.randomUUID();
|
|
120
111
|
const re = new RegExp(`^${words}`);
|
|
112
|
+
|
|
113
|
+
let ac = null;
|
|
121
114
|
const p = new Promise((resolve, reject)=>{
|
|
115
|
+
ac = watchDogTimer(timeout, "make connection", ()=>{
|
|
116
|
+
sendPty(hostInfo.masterPty, "\n", debugSendMasterPty, 137);
|
|
117
|
+
sendPty(hostInfo.masterPty, "exit\n", debugSendMasterPty, 138);
|
|
118
|
+
|
|
119
|
+
const err = new Error(`can not connect within ${timeout} sec`);
|
|
120
|
+
err.host = hostInfo.host;
|
|
121
|
+
err.user = hostInfo.user;
|
|
122
|
+
err.port = hostInfo.port;
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
|
|
122
126
|
let done = false;
|
|
123
127
|
hostInfo.masterPty.onData((data)=>{
|
|
124
128
|
if (done) {
|
|
@@ -157,7 +161,9 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
157
161
|
await p;
|
|
158
162
|
debug(`connected to ${hostInfo.host}`);
|
|
159
163
|
} finally {
|
|
160
|
-
ac
|
|
164
|
+
if (ac !== null) {
|
|
165
|
+
ac.abort();
|
|
166
|
+
}
|
|
161
167
|
}
|
|
162
168
|
}
|
|
163
169
|
|