iiegor / xat-server

A Node.js private server of xat.com
8 stars 2 forks source link

Duplicated client not closing correctly #16

Closed iiegor closed 8 years ago

iiegor commented 8 years ago

Preview

img

Details

This issue appeared since the introduction of c2f440740fcbeef86703f326fc85ade2443a1a43. Probably related with handler.coffee#L64 and server.coffee#L39.

huumanoid commented 8 years ago

This happens because disconnection of duplicated client handles after j2 dispatching.

Look: Let's say we are using profile with id 123

  1. Connecting first time What is going on when we are connecting second time?
  2. j2 dispatching 2.1 User.process 2.2 then: here we raising socket.end() event and setting global.Server.clients[123] = newhandler 2.3 Chat.joinRoom
  3. socket.on 'end' in server.coffee here we perform delete @clients[client.id] where client.id is 123

so what do we have? there is no 123 user in clients array.

The way to fix: set client.id to dummy value after raising socket.end(). for ex.: client.id = -(1<<31)

Looks.. bad. But works.

huumanoid commented 8 years ago

check out the other, better way to fix it. huumanoid/xat-server@4cf61cdbd43dbc8319ab7477b7cb4a9484f81d29 it's better because fix other two bugs related with dup handling.

iiegor commented 8 years ago

Hey @HuuMaNoID, thanks for the info, I solved this by another way (see on branch improve/client-management), what do you think?

huumanoid commented 8 years ago

Your solution looks OK.