panrouter 5.4.5 → 5.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/package.json +1 -1
- package/pool-worker.mjs +33 -8
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -178,21 +178,41 @@ function scheduleReconnect() {
|
|
|
178
178
|
|
|
179
179
|
function handleUpgrade() {
|
|
180
180
|
log("收到主控升级指令,开始升级...", "WARN");
|
|
181
|
-
//
|
|
182
|
-
|
|
181
|
+
// 彻底断开——remove 所有 ws 事件监听,不让 close 事件触发 reconnect
|
|
182
|
+
stopHeartbeat();
|
|
183
|
+
if (reconnectTimer) {
|
|
184
|
+
clearTimeout(reconnectTimer);
|
|
185
|
+
reconnectTimer = null;
|
|
186
|
+
}
|
|
183
187
|
if (ws) {
|
|
188
|
+
ws.removeAllListeners();
|
|
184
189
|
try { ws.close(1000, "Upgrading"); } catch {}
|
|
185
190
|
ws = null;
|
|
186
191
|
}
|
|
187
|
-
stopHeartbeat();
|
|
188
192
|
|
|
189
193
|
const pkgPath = path.join(__dirname, "package.json");
|
|
190
194
|
const oldVersion = JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
|
|
191
|
-
log(`当前版本: v${oldVersion}
|
|
195
|
+
log(`当前版本: v${oldVersion}`);
|
|
196
|
+
|
|
197
|
+
// 先检查 npm registry 是否有新版,避免 Windows 下 EBUSY
|
|
198
|
+
let hasNewer = false;
|
|
192
199
|
try {
|
|
193
|
-
execSync("npm
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
const latest = execSync("npm view panrouter version", { stdio: 'pipe', timeout: 10000 }).toString().trim();
|
|
201
|
+
hasNewer = latest !== oldVersion;
|
|
202
|
+
if (!hasNewer) {
|
|
203
|
+
log(`已是 v${latest}(最新版),跳过 npm install`, "OK");
|
|
204
|
+
}
|
|
205
|
+
} catch {
|
|
206
|
+
// 网络问题等,保守假设有新版本
|
|
207
|
+
hasNewer = true;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (hasNewer) {
|
|
211
|
+
try {
|
|
212
|
+
execSync("npm install -g panrouter@latest", { stdio: "inherit", timeout: 120000 });
|
|
213
|
+
} catch (e) {
|
|
214
|
+
log(`升级失败: ${e.message},仍尝试重启`, "ERR");
|
|
215
|
+
}
|
|
196
216
|
}
|
|
197
217
|
|
|
198
218
|
// 从磁盘重新读(跳过 require 缓存)
|
|
@@ -231,6 +251,11 @@ function handleUpgrade() {
|
|
|
231
251
|
|
|
232
252
|
async function doRestart() {
|
|
233
253
|
isShuttingDown = false;
|
|
254
|
+
// 确保重连定时器已经清掉,避免和 connectToHub 竞态
|
|
255
|
+
if (reconnectTimer) {
|
|
256
|
+
clearTimeout(reconnectTimer);
|
|
257
|
+
reconnectTimer = null;
|
|
258
|
+
}
|
|
234
259
|
const serverOk = await ensureServer();
|
|
235
260
|
if (!serverOk) {
|
|
236
261
|
log("代理服务重启失败", "ERR");
|
|
@@ -322,7 +347,7 @@ function startHeartbeat() {
|
|
|
322
347
|
stopHeartbeat();
|
|
323
348
|
heartbeatTimer = setInterval(() => {
|
|
324
349
|
safeSend({ type: "ping" });
|
|
325
|
-
},
|
|
350
|
+
}, 15000);
|
|
326
351
|
}
|
|
327
352
|
|
|
328
353
|
function stopHeartbeat() {
|