Skip to content

Gateway hits macOS fd limit (256): OSError Too many open files #30230

@BournYSix

Description

@BournYSix

Problem

On macOS, the default launchctl limit maxfiles soft limit is 256. Hermes gateway processes with multiple profiles + MCP servers routinely exceed this:

trade-paper gateway: 286 fds (198 IPv4, 50 REG, 20 PIPE)

When the limit is hit, any file operation fails with:

OSError: [Errno 24] Too many open files: '.sessions_*.tmp'

This crashes session saves, kanban dispatches, and any tool that opens files.

Root cause

  • Each MCP server subprocess (playwright, sequential-thinking, memory, brave-search) maintains persistent pipes/sockets
  • Multiple profiles each run their own gateway with independent MCP connections
  • Hermes never closes idle MCP connections or monitors fd usage
  • No startup warning when ulimit -n is near capacity

Workaround

Manually add SoftResourceLimitsNumberOfFiles: 4096 to each gateway launchd plist.

Suggested fixes

  1. Startup detection: Check resource.getrlimit(resource.RLIMIT_NOFILE) at gateway start, warn if soft limit < 1024
  2. MCP lazy init: Don't connect all MCP servers at startup — connect on first tool call
  3. Idle MCP timeout: Close MCP connections idle for N minutes, reconnect on demand
  4. Periodic fd check: Log warning in gateway loop if fd count exceeds 80% of soft limit

Environment

  • macOS 26.5 (Apple Silicon)
  • Hermes 3 profiles (default, research, trade-paper)
  • 6 MCP servers configured
  • Python 3.x, launchd-managed gateways

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions