Skip to content

socket.join() sometimes (!) does not work #2311

Closed
@helios1138

Description

@helios1138

I have a system in which a lot of clients are constantly joining and leaving rooms and I see this weird behavior in which I do:

socket.join(someRoom);

and them on the next line I have:

console.log(io.of('/').adapter.rooms[someRoom][socket.id])

which prints true most of the time, but sometimes I get undefined

in Socket class source code I see this line that stops socket from joining the room:

if (~this.rooms.indexOf(room)) return this;

So I now I see that problem is that adapter.rooms and socket.rooms are out of sync for some reason.

Also in the Adapter.prototype.add() I see this:

if (fn) process.nextTick(fn.bind(null, null));

So apparently adapter.rooms and socket.rooms are updated in different event loops. Might this be causing the problem?

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