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

Socket still fires event after disconnect #3095

Closed
1 task done
wagenaartje opened this issue Oct 21, 2017 · 2 comments
Closed
1 task done

Socket still fires event after disconnect #3095

wagenaartje opened this issue Oct 21, 2017 · 2 comments

Comments

@wagenaartje
Copy link

wagenaartje commented Oct 21, 2017

You want to:

  • report a bug

Current behaviour

I'm sending certain tasks to connected clients (all using Chrome), the clients then send back the result of the task. Of course, all tasks need to be completed and thus a task should be sent to another client when the first client disconnects.

So this is what is happening:

  • SERVER sends task to CLIENT
  • CLIENT disconnects (fires socket.on('disconnect', ...))
  • SERVER removes CLIENT from the task's client list and appoints task to new CLIENT2
  • CLIENT sends a message with task results (fires socket.on('completion', ...))

I have no idea how this is even possible. I have spent literally days trying to understand why the server would freeze and I just discovered this by doing the following:

  socket.on('completion', function (data) {
    console.log('Completing task...', socket.connected); // logs 'false'
    // do something
  });

Steps to reproduce (if the current behaviour is a bug)

I can't really give 'steps'. All I can say is that i'm sending tasks to the client that are finished within a second, and i'm sending 1000s of them sequentially. I should also mention that each client has X sockets doing tasks, one for every CPU core.

Expected behaviour

Should not fire an event when disconnected.

Setup

  • OS: Windows 10
  • browser: Chrome
  • socket.io version: latest

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@xPaw
Copy link

xPaw commented Oct 21, 2018

I believe I found out why this happens.

If I'm reading the code right, it emits normal events in process.nextTick in ondecoded and then in dispatch, but it appears that onclose would be emitted instantly, so it can be 2 ticks behind?

Could any of the developers confirm that this is what is happening?

@darrachequesne
Copy link
Member

For future readers: this was (finally) fixed by 494c64e and included in [email protected].

darrachequesne added a commit that referenced this issue Jun 26, 2022
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
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

3 participants