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

Redis ReplyError when pulling with xreadgroup on empty subscribed events #10273

Open
nizans opened this issue May 13, 2024 · 2 comments · May be fixed by #10297
Open

Redis ReplyError when pulling with xreadgroup on empty subscribed events #10273

nizans opened this issue May 13, 2024 · 2 comments · May be fixed by #10297

Comments

@nizans
Copy link

nizans commented May 13, 2024

Which package is this bug report for?

brokers

Issue description

Hey,
First of all, Thanks for this package!

I noticed that PubSubRedisBroker errors when it is trying to pull using xreadgroup without subscribed events.

The error is a Redis ReplyError because the command is incomplete because it has no streams keys in it
Heres the error:

ReplyError: ERR syntax error
    at parseError (C:\dev\playground\discord-js-redis-broker-reproduce\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (C:\dev\playground\discord-js-redis-broker-reproduce\node_modules\redis-parser\lib\parser.js:302:14) {
  command: {
    name: 'xreadgroup',
    args: [
      'GROUP',
      'channel',
      '7b60fb0c836ce1d6320712e4b74642c30a9c942d',
      'COUNT',
      '10',
      'BLOCK',
      '5000',
      'STREAMS'
    ]
  }
}

The error shows clearly that the command simply missing the stream keys, which at that point don't exists.

Am I doing something wrong here?

If not I think this error can be avoided easily by checking if there's any subscribed events in before the next poll

Ill gladly open a PR for that.

Thanks

Code sample

import { PubSubRedisBroker } from "@discordjs/brokers";
import { Redis } from "ioredis";

const broker = new PubSubRedisBroker({ redisClient: new Redis() });

await broker.subscribe("channel", ["event"]);

broker.on("event", (message) => {
  console.log(message);
});

broker.on("error", (error) => {
  // This will be a ReplyError on the next poll
  console.error(error);
});

await broker.publish("event", "message");

// This will make the BaseRedis subscribedEvents empty
// But BaseRedis listen will continue to poll until errors
await broker.unsubscribe("channel", ["event"]);

Versions

  • "@discordjs/brokers": "^0.2.2"
  • Node 18
  • "ioredis": "^5.3.2"

Issue priority

Low (slightly annoying)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

@didinele
Copy link
Member

If not I think this error can be avoided easily by checking if there's any subscribed events in before the next poll

yup. odd bug. can I ask what the use case here is? are you dynamically subscribing/unsubscribing to certain keys? I'd never see myself running into this personally

I'll PR a fix soon-ish, this also made me notice the destroy method should completely stop polling.

@nizans
Copy link
Author

nizans commented May 13, 2024

Sure, In my case I'm creating a stream per user, subscribing when a user connected via socket and unsubscribing on disconnect. so In this case when last user disconnects this error will occur.

I played around a bit and changing this line

to while (this.subscribedEvents.size > 0) seems to work.. not sure if its enough though

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

Successfully merging a pull request may close this issue.

3 participants