openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Bug: socketService.ts once() listeners become permanent on() when queued before connection

Open Liohtml opened this issue 6 months ago • 0 comments

Summary

app/src/services/socketService.ts — the once() method registers listeners in pendingListeners when the socket isn't connected yet. When the socket later connects, pending listeners are flushed using socket.on(event, callback) instead of socket.once(event, callback).

This means listeners registered via once() before socket connection fire on every subsequent event, not just the first one.

Location

app/src/services/socketService.ts — once() method + pending listener flush logic

Impact

Medium — Unexpected repeated handler execution for one-shot listeners. Can cause duplicate state mutations, redundant API calls, or UI flicker.

Suggested Fix

Add a once: boolean flag to the pending queue entry and flush with the matching method:

pendingListeners.push({ event, callback: wrappedCallback, once: true });
// In flush:
if (pending.once) socket.once(pending.event, pending.callback);
else socket.on(pending.event, pending.callback);

Liohtml avatar May 16 '26 14:05 Liohtml