Coder Social home page Coder Social logo

Comments (14)

rauchg avatar rauchg commented on July 30, 2024

That's awful.

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

Although client tracking usage is discouraged, I forgot to add it to the README

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

It actually looks like it's potentially a race condition instead.

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

@nicokaiser
I cleaned up some of your clientTracking work here: https://github.com/LearnBoost/websocket.io/compare/fix-tracking
Is there a chance for a race condition here? Can a client reserve a i and then by the time open fires the i is a different client?

from websocket.io.

railnerd avatar railnerd commented on July 30, 2024

I had assumed the use of "i" was a typo, not a reference to the other "i" in the module.

from websocket.io.

railnerd avatar railnerd commented on July 30, 2024

actually, the other issue is that you end up with a clients array full of nulls. Couldn't you track clients using an associative array instead?

if (self.options.clientTracking) {
  self.clients[client] = client;
  self.clientsCount++;
  client.on('close', function () {
    delete self.clients[client];
    self.clientsCount--;
  });
}

from websocket.io.

railnerd avatar railnerd commented on July 30, 2024

(and yes I agree that fix was god awful) ;-)

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

No I meant an awful bug haha!! Thanks for reporting this

from websocket.io.

railnerd avatar railnerd commented on July 30, 2024

BTW: I still think there is a leak where the clients array never shrinks. I'm a fairly recent student of Javascript so apologies if I get any of this wrong, I'm an OCD C programmer by day— I started playing with node & socket.io on a hobby project and have been smitten— haven't had this much fun programming since 5th grade (and trust me, that was a LONG time ago).

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

Yes. We should delete instead of setting to null

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

And clients should be a {}

from websocket.io.

ruxkor avatar ruxkor commented on July 30, 2024

While inspecting the same blocks because of issue 42, I think that using an object is actually not the best solution for it:

While the access to single server.clients would be efficient, slicing, etc. would be much more cumbersome. The other point is that even with the object usage, i would steadily increase.

In commit 68f8258f97 in my fork I addressed this issue by

  • saving the closed connections (i.e. the ones that will be set to null) in an array, and
  • reusing these indices when a new connection is created

this way, the maximum array size is bound to the maximum number of concurrent connections, which seems to be the optimal tradeoff for my uses.

from websocket.io.

rauchg avatar rauchg commented on July 30, 2024

I like that approach, would you mind submitting a pull request? Thanks!

from websocket.io.

ruxkor avatar ruxkor commented on July 30, 2024

here it is :) the changes are only about the array filling, without your fix-tracking branch (i.e. it differs from the commit I linked to in the last comment).

from websocket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.