skyware-js / bot

A framework for building bots on Bluesky.
Mozilla Public License 2.0
27 stars 5 forks source link

Stopping a Bot? #2

Closed aalku closed 2 months ago

aalku commented 5 months ago

Hello! Great software!! It's being really useful to me.

I have a question and I will give you a context.

My question is in the title. How can I stop a Bot instance? I cannot find methods like "close" or "disconnect". I guess if I don't stop them and I create new ones that would create a memory leak and maybe quota issues with the APIs.

The context is that I'm using your Firehose library to search for certain posts in the Firehose, in real time, and then I use your Bot library to gather more data about them... and after some hours, maybe more than a day, I see the Firewhose is still working but somethings wrong in my code. I'm trying to debug the problem. Maybe the bot is not behaving as before? Does the websocket reconnect if it disconnects because a network problem or server reset? I wonder if I can restart the Bot or dispose it and make a new instance, but I would like to stop it for that.

I'll keep debugging my software because it's all probably my fault in any case.

Thanks for any answer you can give me!

aalku commented 5 months ago

Hi. I introduced a method call arround many promises to throw a timeout error if they don't resolve or reject un 2 minutes and I think I narrowed down the problem to node fetch() method stopping working after some hours and instead of throwing errors (rejecting promises) it does nothing. I can be wrong or that might be a node bug or networking error (DNS maybe).

aalku commented 4 months ago

I think I found the bug in your code.

Here you create the rate limiter with 3000 operations per 300*1000 seconds, so a thousand times less than the official rate. https://github.com/skyware-js/bot/blob/7fa2b6eebbab85eb67afa2f5d51da71d8f54bb14/src/bot/Bot.ts#L139

As you can see it's supossed to be seconds and I guess you treat it as if it was milliseconds: https://github.com/Borewit/rate-limit-threshold

So after some time your rate-limited client stops making my requests with sleeps, allowing me only 3000 calls per 3.5 days.