Skip to content

fix(gateway): exit 0 on EADDRINUSE port conflict to prevent crash-loops (#28191) - #29499

Closed
BlueBirdBack wants to merge 2 commits into
openclaw:mainfrom
BlueBirdBack:fix/issue-28191-eaddrinuse-exit-zero
Closed

BlueBirdBack wants to merge 2 commits into
openclaw:mainfrom
BlueBirdBack:fix/issue-28191-eaddrinuse-exit-zero

Conversation

@BlueBirdBack

Copy link
Copy Markdown
Contributor

Problem

When a second gateway instance tries to start and finds the port already bound (EADDRINUSE), it throws a GatewayLockError which propagates as a non-zero exit (code 1). Under systemd with Restart=on-failure (the default), exit 1 triggers an immediate restart — which hits the same error — creating a tight crash-loop that burns CPU and floods logs.

Reproduced in openclaw-lab:2026.2.26 (Docker): second gateway exits code 1 on port conflict.

Root Cause

src/gateway/server/http-listen.ts:26-31 throws GatewayLockError (with cause.code === "EADDRINUSE") on port conflict. This is caught in src/cli/gateway-cli/run.ts and unconditionally calls defaultRuntime.exit(1).

Introduced by commit bcbfb357be (Peter Steinberger, 2026-01-14). Partially mitigated by 16ccd5a87 (ThrottleInterval for launchd) and dd07c06d0 (tighter restart loop), but the core EADDRINUSE → clean exit was never addressed.

Fix

In the GatewayLockError catch block in run.ts, inspect err.cause.code. If it is EADDRINUSE, the port is already owned by a live gateway — this process has nothing to do, so exit 0. The error message and diagnostics are still printed. All other GatewayLockError variants (lock-file timeout, stale lock, etc.) continue to exit 1.

const lockCause = (err as GatewayLockError).cause;
const isPortConflict =
  lockCause != null &&
  typeof lockCause === "object" &&
  (lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
defaultRuntime.exit(isPortConflict ? 0 : 1);

Testing

  • Existing gateway-cli.coverage.test.ts GatewayLockError tests still pass (they do not set cause.code === EADDRINUSE).
  • Port-conflict path now exits 0 — service managers with Restart=on-failure will not restart the gateway.

Fixes #28191

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Feb 28, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b2e199402

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cli/gateway-cli/run.ts Outdated
lockCause != null &&
typeof lockCause === "object" &&
(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
defaultRuntime.exit(isPortConflict ? 0 : 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep non-gateway EADDRINUSE as startup failure

This now returns exit code 0 for any EADDRINUSE, but that errno is also raised when an unrelated process is bound to the configured port (for example, another service or stale local dev process). In those cases startup still failed, and returning success prevents supervisors using Restart=on-failure from retrying, which can leave the gateway permanently down until manual intervention. Please only exit 0 when you can confirm the listener is an already-running OpenClaw gateway instance; otherwise keep the non-zero exit.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a crash-loop issue where a second gateway instance would repeatedly restart when encountering a port conflict. The fix correctly distinguishes between EADDRINUSE (port already bound by another gateway) and other lock acquisition failures, exiting cleanly (code 0) only for port conflicts to prevent service managers from restarting.

  • The implementation uses defensive null/undefined checks before accessing cause.code
  • The logic correctly handles all edge cases (null cause, non-object cause, missing code property)
  • Error messages and diagnostics are still printed for observability
  • The comment clearly explains the rationale for this behavior

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The change is minimal, focused, and solves a specific problem (preventing crash-loops on port conflicts). The implementation is defensive with proper null/undefined checks, handles all edge cases correctly, and maintains error reporting for observability. The logic only affects the exit code for a specific error condition (EADDRINUSE) while preserving existing behavior for all other error cases.
  • No files require special attention

Last reviewed commit: 3b2e199

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from 3b2e199 to 35b0333 Compare February 28, 2026 13:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35b0333c1a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cli/gateway-cli/run.ts Outdated
lockCause != null &&
typeof lockCause === "object" &&
(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
defaultRuntime.exit(isPortConflict ? 0 : 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return failure for unknown EADDRINUSE conflicts

listenGatewayHttpServer converts any socket bind EADDRINUSE into GatewayLockError without verifying the owner process (src/gateway/server/http-listen.ts:26-31), so this new exit(0) path also treats unrelated listeners (for example, another local service already on the configured port) as a successful gateway start. In that scenario the gateway is still down, but callers/supervisors that rely on non-zero status (especially Restart=on-failure setups and health scripts) will stop retrying because startup is reported as success.

Useful? React with 👍 / 👎.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Mar 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 247294cd8e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +394 to +397
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,
}).catch(() => null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include resolved credentials in EADDRINUSE probe

When EADDRINUSE is hit, this branch probes ws://127.0.0.1:${port} without passing auth, even though this command already resolved token/password earlier. probeGateway only reports ok after a successful authenticated connect and follow-up RPCs, so if the already-running gateway requires auth (a common production setup), the probe returns false and the process still exits 1, leaving Restart=on-failure crash-loops unresolved in exactly the scenario this change is meant to fix.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe the configured bind host, not only loopback

The probe hardcodes 127.0.0.1, so duplicate-start detection fails when the gateway is intentionally bound to a non-loopback custom host (for that mode the server listens on the configured host, not loopback aliases). In that valid configuration, EADDRINUSE from an already-running gateway still leads to probe failure and exit 1, so supervisors continue restart loops instead of treating the existing instance as healthy.

Useful? React with 👍 / 👎.

@BlueBirdBack

Copy link
Copy Markdown
Contributor Author

Still active — pushed a fix for the Codex P1 review (commit 247294cd8):

Issue: The previous fix exited 0 for any EADDRINUSE, including when an unrelated process holds the port. Supervisors with Restart=on-failure would stop retrying, leaving the gateway silently down.

Fix: When EADDRINUSE is detected, probe ws://127.0.0.1:<port> with a 3-second timeout to confirm an OpenClaw gateway actually answers there. Exit 0 only on a successful probe; exit 1 if the probe fails (foreign process or transient bind error).

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from 247294c to 95bc5ba Compare March 6, 2026 07:55
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Mar 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95bc5baf68

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +424 to +427
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,
}).catch(() => null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reuse resolved credentials in EADDRINUSE probe

When handling EADDRINUSE, the new probe omits auth even though this command already resolved token/password earlier. probeGateway only returns ok after a successful authenticated connection and follow-up RPCs, so if the already-running gateway is in token/password mode (a common production configuration), this probe returns not-ok and the process still exits non-zero, preserving the restart crash-loop this change is meant to prevent.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe the actual bind host instead of loopback

The duplicate-instance check hardcodes ws://127.0.0.1:${port}, but the gateway can be configured to bind to a specific non-loopback host (bind=custom with customBindHost). In that valid setup an already-running gateway will not accept loopback connections, so the probe reports failure and startup exits non-zero even though the port conflict is the expected “already running” case.

Useful? React with 👍 / 👎.

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from 95bc5ba to e85222e Compare March 6, 2026 08:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e85222e8c4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +424 to +426
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle trusted-proxy mode in EADDRINUSE probe

In trusted-proxy auth mode, this duplicate-instance check cannot succeed because the probe is launched without any proxy-auth context, and probeGateway only supports token/password auth inputs (src/gateway/probe.ts), so an already-running trusted-proxy gateway is still treated as a startup failure and exits non-zero. That means Restart=on-failure crash loops remain for trusted-proxy deployments even though the port conflict is the expected "already running" case.

Useful? React with 👍 / 👎.

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from e85222e to 4a4456b Compare March 7, 2026 08:37
@openclaw-barnacle openclaw-barnacle Bot removed the gateway Gateway runtime label Mar 7, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a4456badc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use wss probe when gateway TLS is enabled

The EADDRINUSE recovery probe always targets ws://127.0.0.1:${port}, but the gateway can run with TLS (gateway.tls.enabled), where the listener is created via createHttpsServer and only accepts wss:// upgrades (src/gateway/server-http.ts:598-600). In that valid configuration, probing over plaintext WS will fail even when another OpenClaw gateway instance is healthy, so this branch exits 1 and supervisors keep restart-looping instead of treating the conflict as “already running.”

Useful? React with 👍 / 👎.

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from 4a4456b to d220d09 Compare March 8, 2026 06:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d220d0900a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +464 to +466
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass resolved auth to the EADDRINUSE probe

The new conflict probe is invoked without credentials, even though this command already resolved token/password auth earlier in runGatewayCommand. probeGateway only returns ok after a successful authenticated connection and follow-up RPCs (src/gateway/probe.ts), so when an existing gateway uses token or password auth, this branch still exits with code 1 and supervisors continue crash-looping instead of treating the instance as already running.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Probe the actual listener endpoint instead of ws://127.0.0.1

The probe URL is hardcoded to ws://127.0.0.1:${port}, which breaks duplicate-instance detection for valid gateway configs that do not listen on plaintext loopback. In particular, TLS mode creates an HTTPS server (src/gateway/server-http.ts) so a plaintext ws:// probe cannot connect, and bind=custom listens on the configured non-loopback host only (src/gateway/server-runtime-config.ts + src/gateway/server-runtime-state.ts), so probing 127.0.0.1 fails; both cases incorrectly return exit code 1 even when an OpenClaw gateway is already running.

Useful? React with 👍 / 👎.

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch 2 times, most recently from 800627f to e1f3c61 Compare March 10, 2026 06:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1f3c618ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +464 to +467
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,
}).catch(() => null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass resolved auth credentials to the EADDRINUSE probe

The new EADDRINUSE recovery path probes without auth, even though this function already resolved token/password credentials earlier in the same command path, so any already-running gateway in token or password mode will fail the probe and still exit non-zero. That means the intended crash-loop mitigation does not work for secured deployments, which are a common production configuration.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe the actual gateway endpoint instead of fixed loopback ws

The probe URL is hardcoded to ws://127.0.0.1:${port}, so duplicate-instance detection fails when the running gateway is not reachable at that exact endpoint (for example TLS-enabled wss:// listeners or non-loopback bind modes like custom/tailnet). In those valid configurations this path still exits with failure on an existing healthy instance, so supervisors continue restart loops.

Useful? React with 👍 / 👎.

@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from e1f3c61 to 5dd7ea8 Compare March 11, 2026 06:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dd7ea80d4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +464 to +467
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,
}).catch(() => null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass resolved auth to EADDRINUSE probe

runGatewayCommand already resolves gateway credentials (tokenValue/passwordValue) before startup, but this probe call omits auth, and probeGateway only sets ok after an authenticated onHelloOk plus follow-up RPCs. In token/password deployments, an already-running gateway will reject this unauthenticated probe, so the new conflict path still exits non-zero and supervisors continue restart loops instead of treating the instance as already running.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe actual bind/scheme instead of fixed ws loopback

The conflict probe is hardcoded to ws://127.0.0.1:${port}, but the gateway can legitimately listen on a non-loopback bind host (bind=custom/other modes) and can run TLS (HTTPS/WSS). In those configurations, this endpoint is not the running listener, so the probe incorrectly fails and the process exits with failure even when the port is held by a healthy OpenClaw gateway instance.

Useful? React with 👍 / 👎.

Ash (Bug Lab) added 2 commits March 12, 2026 11:30
… foreign process

Addresses Codex P1 review: the previous fix exited 0 for any EADDRINUSE,
including when an unrelated process (another service, stale dev server) holds
the configured port. In that case the gateway is still down but supervisors
with Restart=on-failure stop retrying because startup reports success.

Fix: when EADDRINUSE is detected, probe ws://127.0.0.1:<port> with a 3s
timeout to confirm an OpenClaw gateway actually answers there. Exit 0 only
when the probe succeeds; exit 1 if the probe fails (foreign process or
transient bind error) so the supervisor retries.
@BlueBirdBack
BlueBirdBack force-pushed the fix/issue-28191-eaddrinuse-exit-zero branch from 5dd7ea8 to 22a52aa Compare March 12, 2026 06:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22a52aaf89

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +464 to +467
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,
timeoutMs: 3000,
}).catch(() => null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass resolved credentials to the port-conflict probe

This probe call omits auth even though runGatewayCommand has already resolved tokenValue/passwordValue, so any already-running gateway in token/password mode will reject the handshake and probeGateway will return ok: false (it only sets ok after authenticated onHelloOk and follow-up RPCs in src/gateway/probe.ts). In those common secured deployments, EADDRINUSE still exits non-zero and supervisors keep restart-looping, so the crash-loop mitigation does not actually work.

Useful? React with 👍 / 👎.

(lockCause as NodeJS.ErrnoException).code === "EADDRINUSE";
if (isPortConflict) {
const probe = await probeGateway({
url: `ws://127.0.0.1:${port}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Derive probe endpoint from active gateway listener settings

The duplicate-instance check hardcodes ws://127.0.0.1:${port}, which does not match valid listener configurations such as TLS-enabled gateways (wss://) or non-loopback/custom bind hosts; in those cases the probe fails even when an OpenClaw gateway is already healthy on the conflicting port. That causes this new branch to fall back to exit 1, so restart-on-failure loops continue in exactly the configurations this change is meant to handle.

Useful? React with 👍 / 👎.

@hydro13 hydro13 self-assigned this Mar 12, 2026
@hydro13

hydro13 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Superseded by #44476 which fixes the same issue with proper auth credential passing and bind/TLS-aware URL resolution. Thanks for identifying this! 🦞

@hydro13 hydro13 closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes size: XS stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway crash-loops on port conflict instead of failing fast

2 participants