Comments (14)
That's awful.
from websocket.io.
Although client tracking usage is discouraged, I forgot to add it to the README
from websocket.io.
It actually looks like it's potentially a race condition instead.
from websocket.io.
@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.
I had assumed the use of "i" was a typo, not a reference to the other "i" in the module.
from websocket.io.
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.
(and yes I agree that fix was god awful) ;-)
from websocket.io.
No I meant an awful bug haha!! Thanks for reporting this
from websocket.io.
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.
Yes. We should delete
instead of setting to null
from websocket.io.
And clients
should be a {}
from websocket.io.
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.
I like that approach, would you mind submitting a pull request? Thanks!
from websocket.io.
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)
- Deprecate #open, use #readyState HOT 1
- server.clients grows over time HOT 2
- Method writeUInt16BE missing in Node 0.4 HOT 1
- Leverage ws parsers HOT 6
- Replace logger by debug?
- Server reference in Socket
- Error handling must be reworked HOT 8
- separate servers for sub-protocols (i.e. Sec-WebSocket-Protocol) HOT 1
- inconsistency between ws.WebSocket.readyState and websocket.io/hybi/WebSocket.readyState HOT 1
- How to filter clients with the origin? HOT 8
- Sub-protocol support broken
- Mask Send Messages
- WSS enable ? HOT 2
- IP Adress HOT 2
- Empty/Undefined error-Events
- Warning in Node 6.1.0 HOT 1
- (node:6620) DeprecationWarning: process.EventEmitter is deprecated. use require('events') instead. HOT 5
- Parser.prototype.__proto__ = EventEmitter.prototype; TypeError: Cannot read property 'prototype' of undefined HOT 4
- Uses vulnerable version of ws
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket.io.