-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SailsJS instance does not know the room subscribers from another sails instance #2593
Comments
I maybe answering my onw issue, need a bit of testing still. It seems I did not configure Redis correctly for the sockets... :-S. I'll get back on this tomorrow. |
Ok, Seems I configured Redis for the socket.js in config correctly. The same for broadcasting in a room, also great. But In my opinion, when one does a subscriber check like: I'm doing something wrong, maybe, but is this correct? SailsJS rules by the way |
@kaasdude Thanks for coming back and answering :)
Indeed. I've been talking to @rauchg about this-- it's complex, but getting close: socketio/socket.io-redis-adapter#15 (comment) |
(my bad, I'll wait and let you close when you've got it sorted) |
@kaasdude btw- since it sounds like you're using heroku, before upgrading to sails v0.11/socket.io 1.0, make sure and read https://github.com/balderdashy/sails-docs/blob/v0.11/concepts/Deployment/Scaling.md#configuring-your-app-for-a-clustered-deployment and https://github.com/balderdashy/sails/blob/0.12/0.11-migration-guide.md#other-configuration-in-configsocketsjs |
(argh sry keep doing that) |
I hope you guys are willing to fix this (even if this issue already is closed now), we really could use this. |
To follow up for future reference: The best way to go about this is to never actually track the socket ids at all-- instead, use your database. Broadcasting works across multiple servers thanks to socket.io-redis, and joining rooms works even with multiple servers thanks to our implementation of the admin bus in sails-hook-sockets. You technically can track socket ids in your app (i.e. store them on your model), but if possible, it's best to treat them as transient. So, for example, if you have a "Canvas" that can be viewed by multiple people, and your UI shows coviewers, then you can track the user id of the coviewer (rather than their socket id). This is also more flexible when they change devices, etc. (And if you support guests that don't have user ids yet, but want to show them as coviewers, manage "Guest" records for them). tldr; avoid using socket.io as a database, and avoid using socket ids to track users or guests. Instead, use your app's models to store and retrieve data, and track users by their user For more tips, see http://sailsjs.org/documentation/concepts/realtime PS. @kaasdude thanks again for your help in figuring out the right solution! |
Situation: We've got 2 SailJS instances ( 2 dyno's on Heroku ).
Sockets are connected and situated in Redis.
On instance 1: First join a room with sails.sockets.join(socket, "aRoom");
On instance 1: Broadcast data: sails.sockets.broadcast(roomName, eventName, data);
When one listens to events on this room, events are received, properly.
When one executes: sails.sockets.subscribers("aRoom"); an array of socket ids is returned.
We can execute this method on both instances, and get the same result.
Now comes the tricky part:
We restart instance 2 for example, (stop/start).
And execute : sails.sockets.subscribers("aRoom"); again.
Now sails does not return subscribers anymore, but we are still able to broadcast to that room?
( It seems the method sails.sockets.subscribers is not aware of the shared sockets in Redis )
Update:
Seems when one subscribes to a model, e.g:
On instance 1: UserAccount.subscribe(socket, 6)
On instance 2: UserAccount.subscribers(6) returns an Array with one socketId, this is ok.
So, it seems Redis does the job, in being an intermediary for socket sessions.
When one restarts instance 2 for instance, and does: UserAccount.subscribers(6), this wil return an empty Array now!??
Besides this, one can do:
UserAccount.message(6, {test:1234}); and this is properly sent and received at the client, but no subscribers?
I'm doing something wrong maybe?
The text was updated successfully, but these errors were encountered: