Skip to content

Update socket.rooms iteration to support Set<string> in for..in loop #367

@ggenzone

Description

@ggenzone

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions