openclaw-abacusai-auth 1.2.7 → 1.2.8
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/index.ts +36 -8
- package/openclaw_output.txt +0 -0
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -570,6 +570,17 @@ async function handleProxyRequest(req: IncomingMessage, res: ServerResponse) {
|
|
|
570
570
|
|
|
571
571
|
async function handleProxyRequestInner(req: IncomingMessage, res: ServerResponse) {
|
|
572
572
|
const path = req.url ?? "/";
|
|
573
|
+
|
|
574
|
+
if (path === "/__kill") {
|
|
575
|
+
console.log("[abacusai] Received /__kill command, stopping zombie proxy...");
|
|
576
|
+
sendJsonResponse(res, 200, { success: true });
|
|
577
|
+
// Execute stop proxy asynchronously after sending response
|
|
578
|
+
setTimeout(() => {
|
|
579
|
+
stopProxy().catch(() => process.exit(0));
|
|
580
|
+
}, 100);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
573
584
|
const target = `${ROUTELLM_BASE}${path}`;
|
|
574
585
|
const headers: Record<string, string> = {
|
|
575
586
|
Authorization: `Bearer ${proxyApiKey}`,
|
|
@@ -703,33 +714,50 @@ function startProxy(apiKey: string): Promise<void> {
|
|
|
703
714
|
});
|
|
704
715
|
});
|
|
705
716
|
|
|
706
|
-
|
|
707
|
-
const tryListen = (port: number
|
|
717
|
+
let killAttempts = 0;
|
|
718
|
+
const tryListen = (port: number) => {
|
|
708
719
|
proxyServer!.listen(port, PROXY_HOST, () => {
|
|
709
720
|
proxyPort = port;
|
|
710
721
|
console.log(`[abacusai] proxy listening on http://${PROXY_HOST}:${proxyPort}`);
|
|
711
722
|
resolve();
|
|
712
723
|
});
|
|
713
724
|
proxyServer!.once("error", (err: NodeJS.ErrnoException) => {
|
|
714
|
-
if (err.code === "EADDRINUSE"
|
|
715
|
-
console.log(`[abacusai] port ${port} in use
|
|
725
|
+
if (err.code === "EADDRINUSE") {
|
|
726
|
+
console.log(`[abacusai] port ${port} in use. Attempting to kill zombie proxy...`);
|
|
727
|
+
killAttempts++;
|
|
728
|
+
if (killAttempts > 5) {
|
|
729
|
+
console.error("[abacusai] Could not kill zombie proxy after multiple attempts.");
|
|
730
|
+
reject(new Error("EADDRINUSE on port 18862 and cannot kill zombie proxy."));
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
716
733
|
proxyServer!.removeAllListeners("error");
|
|
717
|
-
|
|
734
|
+
|
|
735
|
+
// Try to kill the zombie proxy by sending it the /__kill command
|
|
736
|
+
const { request } = require("node:http");
|
|
737
|
+
const req = request(`http://${PROXY_HOST}:${port}/__kill`, { method: 'GET' }, (res: IncomingMessage) => {
|
|
738
|
+
res.resume();
|
|
739
|
+
});
|
|
740
|
+
req.on('error', () => { }); // Ignore network errors
|
|
741
|
+
req.end();
|
|
742
|
+
|
|
743
|
+
console.log(`[abacusai] Waiting 1s for port ${port} to free up...`);
|
|
744
|
+
setTimeout(() => {
|
|
745
|
+
// Create fresh proxyServer to avoid closed state issues
|
|
718
746
|
proxyServer = createServer((req, res) => {
|
|
719
747
|
handleProxyRequest(req, res).catch((e) => {
|
|
720
748
|
console.error("[abacusai] proxy error:", e);
|
|
721
749
|
sendJsonResponse(res, 500, { error: { message: String(e) } });
|
|
722
750
|
});
|
|
723
751
|
});
|
|
724
|
-
tryListen(port
|
|
725
|
-
});
|
|
752
|
+
tryListen(port);
|
|
753
|
+
}, 1000);
|
|
726
754
|
} else {
|
|
727
755
|
reject(err);
|
|
728
756
|
}
|
|
729
757
|
});
|
|
730
758
|
};
|
|
731
759
|
|
|
732
|
-
tryListen(PROXY_PORT_DEFAULT
|
|
760
|
+
tryListen(PROXY_PORT_DEFAULT);
|
|
733
761
|
});
|
|
734
762
|
}
|
|
735
763
|
|
|
Binary file
|