Skip to content

[Bug]: Feishu monitor state cleanup incomplete - potential memory leak in httpServers Map #48183

@ai-nurmamat

Description

@ai-nurmamat

Summary

The Feishu plugin's monitor state cleanup in monitor.state.ts has a potential memory leak. When stopping the monitor, the httpServers are closed but the Map entries are deleted immediately without waiting for the server to fully close.

Steps to Reproduce

  1. Configure OpenClaw with multiple Feishu accounts
  2. Start the gateway (Feishu monitor starts)
  3. Repeatedly restart the gateway or reload Feishu accounts
  4. Observe memory usage increasing over time

Expected Behavior

When stopFeishuMonitorState() is called, all resources should be properly released:

  • WebSocket clients should disconnect
  • HTTP servers should close and release ports
  • All Map entries should be cleared

Actual Behavior

In monitor.state.ts:145-150:

The issue is that server.close() is asynchronous but the code doesn't wait for the 'close' event before clearing the Map. This can cause:

  1. Memory leak - server object references retained
  2. Port binding issues - port not fully released before next start
  3. Resource leak - incomplete cleanup

Environment

  • OpenClaw version: 2026.3.x
  • Feishu plugin: All versions

Root Cause Analysis

In monitor.state.ts, the function stopFeishuMonitorState() calls server.close() synchronously but doesn't wait for the callback. This is a classic async cleanup bug.

Proposed Solution

Use the 'close' event to ensure proper cleanup:

Or alternatively, use server.closeAllConnections() for faster cleanup in Node.js.

Labels

bug, memory-leak, feishu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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