ExordiumX / selfcore

11 stars 5 forks source link

What causes the 3 hour limit? How does one close a gateway? #4

Open ryanm opened 1 year ago

ryanm commented 1 year ago

As others have said, gateways have a lifespan of (roughly) 3 hours. After that they stop working. The stream ends.

What causes the gateway connection to silently fail?

Hypothesis: The token has expired. (False.) If I restart my node app, the token works again.

How do I detect when a failure occurs?

Hypothesis: If I wrap gateway.on('message', callback) in a try-catch it might throw an error. I will try that.

In any case, I see 3 options:

  1. Start a new instance of selfcore every 2 hours or so. (But how do I close running connections? It doesn't appear that's possible in selfcore today. I would have to restart the entire node app every 2 hours, which I could do. But would that politely close the connection, or would the connection stay open?)
  2. Try a different library, like discord.js. I did that already and found the documentation confusing.
  3. Fork this repo. Research & fix the bug. (I read the code but don't understand it. So I put a high estimate (20 hours) on this approach.)

All I want: To fetch messages from a public discord channel that I do not admin. Selfcore provides the real-time stream, and I figured I would hunt for another library to do one-time downloads.

Any guidance would be greatly appreciated.

MathijsBlok commented 1 year ago

The connection should be reestablished after it closed, and for that the "close" message should be handled from the websocket. For an example that keeps working endlessly checkout https://gitlab.com/MathijsBlok/discord-mirror