Kick out Meteor Users

Hi!

I have a nightly sync that runs and this can be problematic if active users are on (they’re subscribed to some expensive subs)

I’m currently logging any open WSs prior to the sync

const activeSockets = Meteor.server.stream_server.open_sockets; console.log(amt of activeUsers are ${activeSockets.length} ${new Date()}); if (activeSockets && activeSockets.length) { for (let socket of activeSockets) { console.log(${inspect(socket)} ${new Date()}`);

                //Exposing the underlying SockJS Object and doing something like the following seems to close the connection
                //socket.close()
            }
        }`

The above works to list metadata about any open sockets. My commented out code seems to work when playing around locally. I.e. I call the socket.close and see my client connection close on its console too. However…my problem is that the connection immediately opens up again. I’m thinking this is due to the Meteor.user being automatically logged in because their tab is still technically open.

Looks like doing something like Meteor.users.update({}, {$set : { "services.resume.loginTokens" : [] }}, {multi:true}); could be what I need. Although I haven’t tested it yet.

Any other patterns or ideas to this? What is the community doing for problems like this?

Ultimately, I aim to spin up another server to handle these syncs that’s outside the web server that clients interact with. But…I may need to issue out this fix prior if need be. Thanks!

You can just send your users to a page which doesn’t have expensive subs, a page with friendly message.

I like that idea too. How do you redirect users to another page from the Server though? (given the SockJS object)

You need codes run on frontend, listen to the server. For example, the meteor style, your frontend subscribes to a publication, you can add a field named redirect, then when you want user to redirect, you set it to true. Your codes on frontend will notice the change and decide to redirect.

1 Like

Design pattern would be have a callback timer on the client that if no input detected, no blur or focus after a TTL limit is set of X minutes or seconds etc then pause connections, on input it clears the countdown and keeps resetting like that. When the countdown concludes it runs the disconnect, when input is detected it reconnects - you could use a state in react to watch for that and display a spinner loading icon while this happens

1 Like

In our case they’ll be forced to be kicked out and so we won’t even check user input. I was thinking maybe a Bert alert with a timer ensuring them to save their work, etc…

Oh that’s way easier. Just have a timer count down and then issue a redirect to the /logout page and maybe set a GET var like /logout?timeout so the template can display a message explaining you were logged out to keep your account secure, your work was saved etc

1 Like