Skip to content

Web Worker memory leak on disconnect #1902

@tanmaysharma2001

Description

@tanmaysharma2001

Description

When using RealtimeClient with the worker: true option, Web Workers are never terminated when the connection is disconnected. This causes memory accumulation as workers continue running indefinitely even after the client has been torn down.

Current behavior:

  • Workers are created in _startWorkerHeartbeat() (line 691)
  • Workers are never terminated in _teardownConnection() (line 628-649)
  • Each disconnect/reconnect cycle leaks one worker
  • Workers continue sending heartbeat messages even when disconnected

Expected behavior:

  • Workers should be terminated when disconnect() is called
  • Worker references should be cleared for garbage collection
  • No orphaned workers should remain after disconnection

I intend to submit a PR for this issue.

Suggested solution

Add a _terminateWorker() private method that properly terminates the Web Worker and clears the reference, then call it during connection teardown and then update _teardownConnection() to call it.

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions