Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ggenzone opened this issue Nov 24, 2023 · 0 comments
Open

Comments

@ggenzone
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant