Skip to content

fix(gateway): WeCom gateway CPU spin when WebSocket enters CLOSING state #28293

@02356abc

Description

@02356abc

Bug Description

When the WeCom (WeWork) WebSocket connection enters WSMsgType.CLOSING state (e.g., during network interruption or server-side close), the _read_events() loop in gateway/platforms/wecom.py does not handle this message type. This causes receive() to immediately return CLOSING again, resulting in a tight loop that consumes 45-100% CPU.

Root Cause

The elif branch checking for terminal WebSocket states only includes:

  • aiohttp.WSMsgType.CLOSE
  • aiohttp.WSMsgType.CLOSED
  • aiohttp.WSMsgType.ERROR

It is missing aiohttp.WSMsgType.CLOSING.

Environment

  • Python 3.11+
  • aiohttp (any version with WSMsgType.CLOSING)
  • Hermes Agent main branch

Reproduction Steps

  1. Start gateway with WeCom platform enabled: hermes gateway run
  2. Trigger a network interruption or wait for server-side close
  3. Observe CPU usage spike to 45-100% in hermes_cli.main gateway run process
  4. Gateway logs show no error, but process is spinning

Expected Behavior

Gateway should recognize CLOSING as a terminal state, close the connection gracefully, and reconnect.

Actual Behavior

CPU spins at 45-100% until process is manually killed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/wecomWeCom / WeChat Work adaptertype/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