cdp-tunnel 2.4.0 → 2.4.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/cli/index.js +13 -3
- package/extension-new/manifest.json +1 -1
- package/package.json +1 -1
- package/server/proxy-server.js +20 -2
package/cli/index.js
CHANGED
|
@@ -181,6 +181,16 @@ function startServer(port, watchdog, autoRestart) {
|
|
|
181
181
|
|
|
182
182
|
child.on('exit', (code, signal) => {
|
|
183
183
|
const now = Date.now();
|
|
184
|
+
const reason = signal ? `信号 ${signal}` : `退出码 ${code}`;
|
|
185
|
+
const logLine = `[${new Date().toISOString()}] [WATCHDOG] 服务器退出: ${reason}\n`;
|
|
186
|
+
fs.appendFileSync(LOG_FILE, logLine);
|
|
187
|
+
|
|
188
|
+
if (code === 0 && !signal) {
|
|
189
|
+
log('gray', ' 服务器正常退出 (code=0),不重启');
|
|
190
|
+
try { fs.unlinkSync(PID_FILE); } catch {}
|
|
191
|
+
process.exit(0);
|
|
192
|
+
}
|
|
193
|
+
|
|
184
194
|
restartTimestamps = restartTimestamps.filter(t => now - t < RESTART_WINDOW);
|
|
185
195
|
restartTimestamps.push(now);
|
|
186
196
|
|
|
@@ -193,7 +203,6 @@ function startServer(port, watchdog, autoRestart) {
|
|
|
193
203
|
process.exit(1);
|
|
194
204
|
}
|
|
195
205
|
|
|
196
|
-
const reason = signal ? `信号 ${signal}` : `退出码 ${code}`;
|
|
197
206
|
console.log('');
|
|
198
207
|
log('yellow', '⚠ 服务器异常退出 (' + reason + '),3 秒后自动重启...');
|
|
199
208
|
console.log(' 重启次数: ' + restartTimestamps.length + '/' + MAX_RESTARTS + ' (60秒内)');
|
|
@@ -456,8 +465,9 @@ program
|
|
|
456
465
|
|
|
457
466
|
if (wasRunning) {
|
|
458
467
|
log('cyan', '🔄 重启服务器...');
|
|
459
|
-
startServer(savedPort,
|
|
460
|
-
|
|
468
|
+
const child = startServer(savedPort, false, config.autoRestart);
|
|
469
|
+
child.unref();
|
|
470
|
+
log('green', '✅ 服务器已重启 (PID: ' + child.pid + ')');
|
|
461
471
|
} else {
|
|
462
472
|
log('cyan', ' 运行 cdp-tunnel start 启动服务器');
|
|
463
473
|
}
|
package/package.json
CHANGED
package/server/proxy-server.js
CHANGED
|
@@ -1556,10 +1556,10 @@ setInterval(() => {
|
|
|
1556
1556
|
|
|
1557
1557
|
// 优雅关闭
|
|
1558
1558
|
process.on('SIGINT', () => {
|
|
1559
|
-
console.log('\n[SERVER] Shutting down...');
|
|
1559
|
+
console.log('\n[SERVER] Shutting down (SIGINT)...');
|
|
1560
|
+
logCDP('SERVER', 'Shutting down (SIGINT)');
|
|
1560
1561
|
clearInterval(heartbeatInterval);
|
|
1561
1562
|
|
|
1562
|
-
// 关闭所有连接
|
|
1563
1563
|
pluginConnections.forEach(ws => ws.close(1001, 'Server shutting down'));
|
|
1564
1564
|
clientConnections.forEach(ws => ws.close(1001, 'Server shutting down'));
|
|
1565
1565
|
|
|
@@ -1571,17 +1571,35 @@ process.on('SIGINT', () => {
|
|
|
1571
1571
|
});
|
|
1572
1572
|
|
|
1573
1573
|
process.on('SIGTERM', () => {
|
|
1574
|
+
console.log('[SERVER] Shutting down (SIGTERM)...');
|
|
1575
|
+
logCDP('SERVER', 'Shutting down (SIGTERM)');
|
|
1574
1576
|
flushAllLogs();
|
|
1575
1577
|
process.exit(0);
|
|
1576
1578
|
});
|
|
1577
1579
|
|
|
1580
|
+
process.on('uncaughtException', (err) => {
|
|
1581
|
+
console.error('[FATAL] Uncaught exception:', err.message, err.stack);
|
|
1582
|
+
logCDP('FATAL', `Uncaught exception: ${err.message}\n${err.stack}`);
|
|
1583
|
+
flushAllLogs();
|
|
1584
|
+
process.exit(1);
|
|
1585
|
+
});
|
|
1586
|
+
|
|
1587
|
+
process.on('unhandledRejection', (reason) => {
|
|
1588
|
+
console.error('[FATAL] Unhandled rejection:', reason);
|
|
1589
|
+
logCDP('FATAL', `Unhandled rejection: ${reason}`);
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1578
1592
|
server.on('error', (err) => {
|
|
1579
1593
|
if (err.code === 'EADDRINUSE') {
|
|
1580
1594
|
console.error(`[FATAL] Port ${PORT} is already in use. Is another cdp-tunnel running?`);
|
|
1581
1595
|
console.error(` Run "cdp-tunnel stop" first, or kill the process on port ${PORT}.`);
|
|
1596
|
+
logCDP('FATAL', `Port ${PORT} already in use (EADDRINUSE)`);
|
|
1597
|
+
flushAllLogs();
|
|
1582
1598
|
process.exit(2);
|
|
1583
1599
|
}
|
|
1584
1600
|
console.error('[FATAL] Server error:', err.message);
|
|
1601
|
+
logCDP('FATAL', `Server error: ${err.message}`);
|
|
1602
|
+
flushAllLogs();
|
|
1585
1603
|
process.exit(1);
|
|
1586
1604
|
});
|
|
1587
1605
|
|