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

When removing sockets from a room, the last socket doesn't get removed #4385

Closed
motsgar opened this issue May 31, 2022 · 1 comment
Closed
Labels
to triage Waiting to be triaged by a member of the team

Comments

@motsgar
Copy link

motsgar commented May 31, 2022

Describe the bug
When removing sockets from a room, the last socket doesn't get removed.

To Reproduce

Socket.IO server version: 4.5.1

Server

this code is from a function that is supposed to reset the state of a specific socket and also reset the state of all other sockets that are in the same game (a specific room)

console.log(io.sockets.adapter.rooms);
console.log(socket.data.currentGameId);
console.log(socket.rooms);

for (const clientId of io.sockets.adapter.rooms.get(socket.data.currentGameId)) {
	const clientSocket = io.sockets.sockets.get(clientId);
	console.log('removing client:', clientId);
	clientSocket.leave(socket.data.currentGameId);
	console.log(io.sockets.adapter.rooms);
	clientSocket.data.currentGameId = undefined;
	clientSocket.data.connectionRole = undefined;
}

console.log(io.sockets.adapter.rooms);
console.log(socket.data.currentGameId);
console.log(socket.rooms);

output:

Map(4) {
  'xBrj-N9JGffU9nXUAAAB' => Set(1) { 'xBrj-N9JGffU9nXUAAAB' },
  'ldbDl34FYbwnBFGEAAAD' => Set(1) { 'ldbDl34FYbwnBFGEAAAD' },
  'AJ2hRyyj5Wtx-iVEAAAF' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' },
  'asdf' => Set(3) {
    'xBrj-N9JGffU9nXUAAAB',
    'ldbDl34FYbwnBFGEAAAD',
    'AJ2hRyyj5Wtx-iVEAAAF'
  }
}
asdf
Set(2) { 'ldbDl34FYbwnBFGEAAAD', 'asdf' }
removing client: xBrj-N9JGffU9nXUAAAB
Map(4) {
  'xBrj-N9JGffU9nXUAAAB' => Set(1) { 'xBrj-N9JGffU9nXUAAAB' },
  'ldbDl34FYbwnBFGEAAAD' => Set(1) { 'ldbDl34FYbwnBFGEAAAD' },
  'AJ2hRyyj5Wtx-iVEAAAF' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' },
  'asdf' => Set(2) { 'ldbDl34FYbwnBFGEAAAD', 'AJ2hRyyj5Wtx-iVEAAAF' }
}
removing client: ldbDl34FYbwnBFGEAAAD
Map(4) {
  'xBrj-N9JGffU9nXUAAAB' => Set(1) { 'xBrj-N9JGffU9nXUAAAB' },
  'ldbDl34FYbwnBFGEAAAD' => Set(1) { 'ldbDl34FYbwnBFGEAAAD' },
  'AJ2hRyyj5Wtx-iVEAAAF' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' },
  'asdf' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' }
}
removing client: AJ2hRyyj5Wtx-iVEAAAF
Map(4) {
  'xBrj-N9JGffU9nXUAAAB' => Set(1) { 'xBrj-N9JGffU9nXUAAAB' },
  'ldbDl34FYbwnBFGEAAAD' => Set(1) { 'ldbDl34FYbwnBFGEAAAD' },
  'AJ2hRyyj5Wtx-iVEAAAF' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' },
  'asdf' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' }
}
Map(4) {
  'xBrj-N9JGffU9nXUAAAB' => Set(1) { 'xBrj-N9JGffU9nXUAAAB' },
  'ldbDl34FYbwnBFGEAAAD' => Set(1) { 'ldbDl34FYbwnBFGEAAAD' },
  'AJ2hRyyj5Wtx-iVEAAAF' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' },
  'asdf' => Set(1) { 'AJ2hRyyj5Wtx-iVEAAAF' }
}
undefined
Set(1) { 'ldbDl34FYbwnBFGEAAAD' }

if later in a other part of code I from a completely new socket connection create a new game with id 'asdf' and start to brodcast data in it, the old connection ('AJ2hRyyj5Wtx-iVEAAAF') starts receiving messages

Expected behavior
The last socket should too get removed from the room, as this causes a problem when the same socket is used on a different game and still recieves messages from the old room if a new game with the same room name was created afterwards

Platform:

  • Device: laptop
  • OS: linux

Might be related to issue #4067

@motsgar motsgar added the to triage Waiting to be triaged by a member of the team label May 31, 2022
@motsgar
Copy link
Author

motsgar commented May 31, 2022

After finding out, that a debug mode exists, I found out that the currentGameId is undefined. This is ofcourse because I set it to undefined previously in the loop that disconnects players...

@motsgar motsgar closed this as completed May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

1 participant