Skip to content
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

Bug: user sessions are never properly cleaned up when a node dies #25

Open
elliottshort opened this issue Dec 20, 2022 · 4 comments
Open

Comments

@elliottshort
Copy link

elliottshort commented Dec 20, 2022

Perhaps I'm overlooking something, but it seems that this query should be { serverId: serverId } instead, yes?
Thanks!

const sessionIds = UserSessions.find({ serverId }, { fields: { userId: true } }).map((session) => {

@copleykj
Copy link
Owner

No, this is just short hand property syntax and is exactly the same functionally.

Can you give further details about the issue?

@elliottshort
Copy link
Author

Hey @copleykj – thanks for the prompt reply! I did some additional troubleshooting and it seems that the varying issues I'm experiencing are likely related to the fact I'm using https://github.com/cult-of-coders/redis-oplog instead of Meteor's built-in. I'll likely have to wind up rolling something of my own unfortunately.

I'll go ahead and close this issue. Cheers!

@copleykj
Copy link
Owner

I'm gonna reopen this cause the rest of the packages in this set are built to work with redis-oplog and if something about it breaks this package I want to understand what might cause this and fix it.

@elliottshort
Copy link
Author

elliottshort commented Dec 20, 2022

Sure thing. The key issue seems to be that that redis oplog doesn't have any means of detecting the db TTL/record expiry that the server presence package relies on: Servers.createIndex({ lastPing: 1 }, { expireAfterSeconds: 10 });

The workaround I've implemented is to use the https://www.npmjs.com/package/mongo-oplog2/v/2.1.2 package and tail the oplog myself -> push the changes to redis so that the logic in the server presence package associated with Servers.find().observe(... works properly.

Workaround:

const oplog = new MongoOplog(
  Meteor.settings["galaxy.meteor.com"].env.MONGO_OPLOG_URL,
  { ns: "meteor.presence:servers" }
);

oplog.tail().then();

oplog.on("delete", (document: OplogDoc) => {
  getRedisPusher().publish(
    "presence:servers",
    EJSON.stringify({
      [RedisPipe.DOC]: { _id: document.o._id },
      [RedisPipe.EVENT]: Events.REMOVE,
      [RedisPipe.FIELDS]: ["createdAt", "lastPing", "watcher"],
    })
  );
});

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants