Skip to content

Socket event listeners are not consistently cleaned up on disconnect #56

Description

@hotoke-no-Kami

Problem
When disconnecting, the code calls socketManager.disconnect() and sets the socket state to null, but it does not explicitly remove event listeners attached to the socket instance.

Why it matters
Remaining listeners can hold references and memory, cause unexpected callbacks if socket instances persist or reconnect, and result in resource leaks.

Affected files

  • src/components/providers/SocketProvider.tsx (cleanup in useEffect and disconnect)
  • src/services/socketManager.ts (disconnect implementation)

Suggested fix

  • Ensure registered listeners (connect, disconnect, connect_error, reconnect, etc.) are removed when disconnecting (socket.off(...)).
  • Prefer that SocketManager manages both registration and teardown of handlers it creates. Implement a handler registry to remove them on disconnect.
  • Add unit tests validating no listeners remain after disconnect.

Notes
This is especially important for SPA environments that may mount/unmount providers repeatedly.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions