Skip to content

Commit 39a95c3

Browse files
author
1bcMax
committed
fix: handle EADDRINUSE gracefully when proxy already running
When openclaw logs --follow triggers plugin reload, the health check may fail but the proxy is still running. Instead of failing with EADDRINUSE, silently reuse the existing proxy. This also includes the 80% buffer for pre-flight balance checks from the previous commit.
1 parent 3eb48b2 commit 39a95c3

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/proxy.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,27 @@ export async function startProxy(options: ProxyOptions): Promise<ProxyHandle> {
453453

454454
// Listen on configured port (already determined above)
455455
return new Promise<ProxyHandle>((resolve, reject) => {
456-
server.on("error", reject);
456+
server.on("error", (err: NodeJS.ErrnoException) => {
457+
// Handle EADDRINUSE gracefully — proxy is already running
458+
if (err.code === "EADDRINUSE") {
459+
// Port is in use, which means a proxy is already running.
460+
// This can happen when openclaw logs triggers plugin reload.
461+
// Silently reuse the existing proxy instead of failing.
462+
const baseUrl = `http://127.0.0.1:${listenPort}`;
463+
options.onReady?.(listenPort);
464+
resolve({
465+
port: listenPort,
466+
baseUrl,
467+
walletAddress: account.address,
468+
balanceMonitor,
469+
close: async () => {
470+
// No-op: we didn't start this proxy, so we shouldn't close it
471+
},
472+
});
473+
return;
474+
}
475+
reject(err);
476+
});
457477

458478
server.listen(listenPort, "127.0.0.1", () => {
459479
const addr = server.address() as AddressInfo;

0 commit comments

Comments
 (0)