openclaw - 💡(How to fix) Fix MCP stdio leak fix incomplete for Docker-wrapped MCP servers (parallel spawn case) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#75323Fetched 2026-05-01 05:35:12
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
2
Timeline (top)
commented ×1

MCP server resource leak from parallel spawn (specialist agents) — fix from #65694 may be incomplete for Docker-wrapped stdio MCP servers.

Root Cause

Root Cause Chain

  1. sessions_spawn with parallel specialists → each isolated session starts its own MCP server
  2. MCP server launched as npm exec @enuno/unifi-mcp-server → Docker wrapper container
  3. Session ends → mcp-stdio-transport.ts close() calls killProcessTree(wrapperPid) → npm process dies
  4. Docker container's PID 1 inside the container never receives SIGTERM → stays running orphaned
  5. Next parallel spawn → new Docker container, old one still present

Fix Action

Workaround

#!/bin/bash
# Kill orphaned unifi-mcp-server containers
docker ps --filter "ancestor=ghcr.io/enuno/unifi-mcp-server:latest" -q | xargs -r docker rm -f
# Run via cron every 5 minutes

Code Example

CONTAINER ID   IMAGE                                   COMMAND                  CREATED        STATUS
3629621920fc   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     18 seconds    (healthy)
8127b0de6d64   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     37 seconds    (healthy)
f54e5d0aa03d   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     2 minutes     (healthy)
...

---

#!/bin/bash
# Kill orphaned unifi-mcp-server containers
docker ps --filter "ancestor=ghcr.io/enuno/unifi-mcp-server:latest" -q | xargs -r docker rm -f
# Run via cron every 5 minutes
RAW_BUFFERClick to expand / collapse

Summary

MCP server resource leak from parallel spawn (specialist agents) — fix from #65694 may be incomplete for Docker-wrapped stdio MCP servers.

Environment

  • OpenClaw Version: 2026.4.21 (also applies to 2026.4.25)
  • Operating System: Ubuntu 22.04 LTS
  • MCP Config: Custom MCP servers via plugins.entries + mcp.servers

Bug Description

When multiple specialist agents (SRE, SE, researcher) are spawned in parallel via sessions_spawn, each fires up its own set of MCP servers. When the session ends, the stdio transport's process-tree kill (killProcessTree) terminates the npm/npx wrapper process but does not propagate the signal to Docker containers launched by those wrappers. Result: orphaned Docker containers accumulate.

Observed Behavior (May 1, 2026)

CONTAINER ID   IMAGE                                   COMMAND                  CREATED        STATUS
3629621920fc   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     18 seconds    (healthy)
8127b0de6d64   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     37 seconds    (healthy)
f54e5d0aa03d   ghcr.io/enuno/unifi-mcp-server:latest   "python -m src.main"     2 minutes     (healthy)
...

11 unifi-mcp-server Docker containers accumulated in ~10 minutes during a parallel spawn session.

Related Context

  • #65694 (closed April 26, 2026) — MCP stdio lifecycle leak; clawsweeper cited fix commit 4a80e61680bb on main
  • Fresh comment on #65694 (April 25, 2026) documented 22 accumulated GitHub MCP + 22 Playwright MCP + 11 UniFi containers on OpenClaw 2026.4.21 — same day the bot claimed the fix was implemented
  • The bot's closing appears to have been automated/verified against main branch code, not a released version with live deployment evidence

Root Cause Chain

  1. sessions_spawn with parallel specialists → each isolated session starts its own MCP server
  2. MCP server launched as npm exec @enuno/unifi-mcp-server → Docker wrapper container
  3. Session ends → mcp-stdio-transport.ts close() calls killProcessTree(wrapperPid) → npm process dies
  4. Docker container's PID 1 inside the container never receives SIGTERM → stays running orphaned
  5. Next parallel spawn → new Docker container, old one still present

Evidence

  • openclaw/openclaw@src/agents/mcp-stdio-transport.ts:112 — killProcessTree kills the npm wrapper but Docker is a child of that wrapper, not the process being killed
  • openclaw/openclaw@src/cron/isolated-agent/run-executor.ts:161 — cleanupBundleMcpOnRunEnd does fire but only kills the outer wrapper
  • Each orphaned container: ~50MB RAM + CPU overhead

Expected vs Actual

  • Expected: After isolated agent session ends, all MCP server processes (including Docker containers) are terminated
  • Actual: npm/npx wrapper dies, Docker container continues running indefinitely

Suggested Fix

  1. Immediate: After killProcessTree, enumerate child Docker containers by parsing /proc/<pid>/children or using cgroup info, then docker rm -f <container> for each orphaned child
  2. Short-term: Add a Docker-aware process reaper that handles the Docker-in-npm-in-stdio-transport chain
  3. Long-term: Use Docker socket or container runtime API to track and clean up MCP containers spawned by the session lifecycle

Impact

  • Docker container leak rate: 1 per parallel spawn (e.g., 4 specialists = 4 containers per run)
  • Escalates with frequency of parallel specialist sessions
  • Eventually exhausts Docker's container namespace or host resources

Workaround

#!/bin/bash
# Kill orphaned unifi-mcp-server containers
docker ps --filter "ancestor=ghcr.io/enuno/unifi-mcp-server:latest" -q | xargs -r docker rm -f
# Run via cron every 5 minutes

extent analysis

TL;DR

Implement a Docker-aware process reaper to handle the Docker-in-npm-in-stdio-transport chain and terminate orphaned containers after a session ends.

Guidance

  • Identify and enumerate child Docker containers after killProcessTree by parsing /proc/<pid>/children or using cgroup info.
  • Use docker rm -f <container> to remove each orphaned child container.
  • Consider implementing a cron job to periodically clean up orphaned containers as a temporary workaround.
  • Review the suggested fix steps, including using the Docker socket or container runtime API for long-term tracking and cleanup.

Example

The provided workaround script can be used as a starting point:

docker ps --filter "ancestor=ghcr.io/enuno/unifi-mcp-server:latest" -q | xargs -r docker rm -f

This script kills orphaned unifi-mcp-server containers and can be run via cron every 5 minutes.

Notes

The current implementation of killProcessTree only kills the npm wrapper process, leaving the Docker container running. A more comprehensive solution is needed to handle the Docker-in-npm-in-stdio-transport chain.

Recommendation

Apply the suggested fix by implementing a Docker-aware process reaper to handle the Docker-in-npm-in-stdio-transport chain, as this will provide a more comprehensive and long-term solution to the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix MCP stdio leak fix incomplete for Docker-wrapped MCP servers (parallel spawn case) [1 comments, 2 participants]