@raevon/n8n-nodes-whatsapp 2.0.8 → 2.0.9
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.
|
@@ -41,7 +41,6 @@ exports.ensureServerRunning = ensureServerRunning;
|
|
|
41
41
|
exports.stopServer = stopServer;
|
|
42
42
|
exports.disconnect = disconnect;
|
|
43
43
|
exports.getWhatsAppCredentials = getWhatsAppCredentials;
|
|
44
|
-
const node_child_process_1 = require("node:child_process");
|
|
45
44
|
const node_path_1 = __importDefault(require("node:path"));
|
|
46
45
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
47
46
|
const node_net_1 = __importDefault(require("node:net"));
|
|
@@ -351,45 +350,24 @@ async function ensureServerRunning(cfg) {
|
|
|
351
350
|
await startServer(cfg);
|
|
352
351
|
return;
|
|
353
352
|
}
|
|
354
|
-
// Port is in use —
|
|
353
|
+
// Port is in use — check if server responds
|
|
355
354
|
try {
|
|
356
355
|
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
|
|
357
356
|
if (res.ok)
|
|
358
357
|
return; // Server alive, use it
|
|
359
358
|
}
|
|
360
359
|
catch { }
|
|
361
|
-
// Port in use but not responding —
|
|
362
|
-
|
|
363
|
-
const out = (0, node_child_process_1.execSync)(`cat /proc/net/tcp | awk '{if(NR>1){split($2,a,\":\");if(strtonum("0x"a[2])==${port})print $10}}'`, { encoding: 'utf-8' }).trim();
|
|
364
|
-
if (out) {
|
|
365
|
-
// Find PID from inode
|
|
366
|
-
const inode = out;
|
|
367
|
-
const pidOut = (0, node_child_process_1.execSync)(`for p in /proc/[0-9]*/fd/*; do if readlink "$p" 2>/dev/null | grep -q "socket:\\[${inode}]"; then echo "$p" | cut -d/ -f3; break; fi; done`, { encoding: 'utf-8' }).trim();
|
|
368
|
-
if (pidOut)
|
|
369
|
-
(0, node_child_process_1.execSync)(`kill -9 ${pidOut}`);
|
|
370
|
-
await new Promise(r => setTimeout(r, 1500));
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
catch { }
|
|
374
|
-
// Try again
|
|
375
|
-
if (await isPortOpen(port)) {
|
|
376
|
-
await startServer(cfg);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
throw new Error(`Port ${port} occupied by unknown process. Restart n8n container to clear.`);
|
|
360
|
+
// Port in use but not responding — stale process, needs container restart
|
|
361
|
+
throw new Error(`Port ${port} occupied. Use "Stop Server" first, or restart n8n container.`);
|
|
380
362
|
}
|
|
381
363
|
async function stopServer(cfg) {
|
|
382
364
|
const port = getPort(cfg);
|
|
383
|
-
//
|
|
365
|
+
// Try graceful shutdown via the server's own /signout endpoint
|
|
384
366
|
try {
|
|
385
|
-
|
|
386
|
-
if (res.ok) {
|
|
387
|
-
servers.delete(port);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
367
|
+
await fetch(`http://127.0.0.1:${port}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
|
|
390
368
|
}
|
|
391
369
|
catch { }
|
|
392
|
-
//
|
|
370
|
+
// Clean up in-memory state
|
|
393
371
|
const state = servers.get(port);
|
|
394
372
|
if (state) {
|
|
395
373
|
if (state.socket) {
|
package/package.json
CHANGED