Skip to content

MCP server processes leaked across sessions — stale PID holds file lock on next reconnect #92569

Description

@StarbloomConsultingHub

Summary

When a new session starts, the gateway spawns fresh MCP server processes but does not reap the previous session's processes. For MCP servers that use exclusive file-locking (embedded databases, SQLite, etc.), this causes the new session's MCP tool calls to fail with lock contention.

Observed behavior

Each session spawns a complete new set of MCP server processes:

  • Session 1: PIDs 663xx range — 5 MCP servers started
  • Session 2: PIDs 667xx range — 5 more MCP servers started, old ones still running

For an MCP server using an embedded database with file-level locking (LadybugDB), the stale process from Session 1 holds an exclusive write lock (fcntl/F_WRLCK) on the .lbdb file. Session 2's process cannot open the database and throws lock errors.

When tool calls fail repeatedly, the gateway's MCP subsystem enters a paused/backoff state that escalates with each retry — self-deepening rather than failing fast.

Expected behavior

The gateway should either:

  1. Reuse MCP server processes across sessions (same process handles all tool calls)
  2. Reap previous session MCP processes before spawning new ones (SIGTERM old PIDs)
  3. Provide a configurable restart strategy per MCP server (e.g., kill-before-spawn semantics)

Workaround

Added stale-PID self-healing in the MCP server init: on lock contention, scan /proc for sibling processes with the same module path, SIGTERM them, then retry. Functional but the MCP server shouldn't manage its own lifecycle.

Environment

  • OpenClaw 2026.6.5 (5181e4f)
  • Linux (WSL2, kernel 6.6.87.2)
  • Affects any MCP server using exclusive file locking (embedded DBs, SQLite, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions