Skip to content

Desktop boot race condition: retry doesn't kill previous backend process → EADDRINUSE on port 9120 #44707

Closed as not planned

Description

@JayC-L

Describe the bug

On Windows, Hermes Desktop frequently fails to start due to a race condition during backend boot:

  1. Desktop launches backend process A on port 9120
  2. Desktop waits for 9120 to become ready, but times out before the Python backend finishes cold start (loading 125MB SQLite DB, scanning skills, etc.)
  3. Desktop considers the boot failed and launches backend process B — without killing process A
  4. Process B tries to bind 9120 → EADDRINUSE because process A is still running
  5. Process B crashes with exit code 1 → Desktop launches process C → same conflict
  6. This creates a zombie process accumulation loop. The only way to recover is to restart Desktop repeatedly ("lottery") until an old process happens to release the port.

Clicking "Repair" in the UI doesn't help — it only kills the "current" tracked process, leaving orphaned processes from previous failed attempts still holding the port.

Logs (desktop.log)

[boot] Starting Hermes backend via existing Hermes CLI
[boot] Waiting for Hermes backend to become ready
[boot] Desktop boot failed: Hermes backend did not become ready: connect ECONNREFUSED 127.0.0.1:9120
[bootstrap] repair requested by renderer; clearing marker + latched failure
[boot] Restarting desktop connection
Hermes backend exited (SIGTERM)
[boot] Starting Hermes backend via existing Hermes CLI
ERROR: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 9120): 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
[boot] Hermes backend exited before it became ready (1).

This pattern repeats 5-10+ times before randomly succeeding.

To Reproduce

  1. Close Hermes Desktop
  2. Ensure no hermes/dashboard python process is running (clean state)
  3. Open Hermes Desktop
  4. Observe: boot takes a long time, often fails with port conflict, requires multiple restarts

Expected behavior

  • Desktop should wait long enough for the backend to finish cold start (configurable timeout)
  • On boot retry, Desktop should kill ALL previous backend processes it spawned, not just the last tracked one
  • Repair should do a clean sweep of all hermes-related python processes

Environment

  • OS: Windows 11
  • Hermes Desktop version: 0.16.0 (release_date: 2026.6.5)
  • Python: 3.11.15
  • state.db size: 125MB (actual data: 3.7MB, 38MB fragmentation)
  • Sessions: 17, Messages: 9275

Additional context

Root cause appears to be two issues:

  1. Boot timeout too aggressive — Windows cold start of the Python backend (venv activation + DB load + skill scan) takes longer than Desktop's wait window
  2. Process cleanup on retry — ensureRuntime in main.cjs doesn't track/kill previously spawned backend processes across retry attempts

Suggested fixes:

  • Increase boot readiness timeout or make it configurable
  • On each retry, ensure all previously spawned backend processes are killed before starting a new one
  • Repair action should scan for and kill all hermes dashboard processes on port 9120

Activity

  1. added
    type/bugSomething isn't working
    P3Low — cosmetic, nice to have
    area/configConfig system, migrations, profiles
    on Jun 12, 2026
  2. teknium1 commented on Jul 14, 2026

    @teknium1
    Collaborator

    This is an automated hermes-sweeper review. The Desktop boot-loop behavior described here is implemented on current main.

    • apps/desktop/electron/main.ts:6750 latches a backend-start failure, preventing subsequent connection attempts from spawning another backend automatically.
    • apps/desktop/electron/main.ts:6795 launches the local backend with OS-assigned port 0, rather than fixed port 9120.
    • apps/desktop/electron/main.ts:6324 and apps/desktop/electron/main.ts:2358 tree-kill the tracked Windows backend via synchronous taskkill /T /F; the repair handler resets that connection at main.ts:7601.
    • apps/desktop/electron/backend-ready.ts:16 uses a 90-second cold-start announcement timeout. This shipped in 6bbacc223 (fix(desktop): make cold-start port-announcement deadline tolerant) and release v2026.7.1.

    The linked PR #45131 addresses the same prior failure mode, but current main already provides the relevant retry, cleanup, ephemeral-port, and cold-start-timeout guarantees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havearea/configConfig system, migrations, profilessweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions