While messing around with a simple Real-Time app, I encountered the following issue:
Issue Summary:
When the socket receives the disconnecting event, it fails to properly notify the associated rooms about the disconnection due to the usage of the incompatible for..in loop (no iteration is performed).
Currently, within the codebase, there exists a situation where the socket.rooms object, defined as a Set<string>, is being iterated using a for..in loop. However, for..in loops aren't compatible with Sets, potentially causing unexpected behavior or errors.
Due to this problem, the server fails to emit the expected room-user-change event.
Proposed Solution:
Refactor the iteration of socket.rooms to use for..of, forEach, or any loop mechanism compatible with Set<string> to ensure proper iteration and avoid potential issues related to incompatible iteration methods.
Additional Information:
$ npm -v
9.8.1
$ node -v
v18.18.2
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
Links
MDN For..in
MDN For..of
Socket.io | socket.rooms
Codebase
While messing around with a simple Real-Time app, I encountered the following issue:
Issue Summary:
When the socket receives the
disconnectingevent, it fails to properly notify the associated rooms about the disconnection due to the usage of the incompatiblefor..inloop (no iteration is performed).Currently, within the codebase, there exists a situation where the
socket.roomsobject, defined as aSet<string>, is being iterated using afor..inloop. However, for..in loops aren't compatible withSets, potentially causing unexpected behavior or errors.Due to this problem, the server fails to emit the expected
room-user-changeevent.Proposed Solution:
Refactor the iteration of
socket.roomsto usefor..of,forEach, or any loop mechanism compatible withSet<string>to ensure proper iteration and avoid potential issues related to incompatible iteration methods.Additional Information:
Links
MDN For..in
MDN For..of
Socket.io | socket.rooms
Codebase