chr-1x / ananas

The Python Bot Framework for Mastodon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Urllib3 failure after a few hours running.

bowlercaptain opened this issue · comments

After running a bot or bots for a while (on a scale of days) this (extremely long, so pastebinned) error is thrown and the bots no longer respond to @replies. @shutdown functions are still called, however. May be related to psf/requests#4248 . Seems to show up when people are making GET requests with the Requests library. Might be caused by poor behavior by the mastodon server? Could be worked-around by catching this error (seems to be about a failure of a persistent connection) and reopening that connection as a result.

I'm aware of this, it's been killing off my bots for weeks. Haven't had time to take a look but I'll ping this issue again when I do.

A few months late, but: As far as I can tell, this is an issue upstream, and there may not be a way to easily contain it in ananas, since PineappleBot is a subclass of Mastodon.py's StreamListener, which is what calls urllib, which is where the error is occurring.

I've suggested a change here which I hope will work around the issue.

Any luck finding causes/solutions?

Latest status with this is I was able to write code to handle it, by attempting to reopen the connection, but the new issue I encountered was that in my test setup (where I reproed by connecting to a local dev mastodon instance and shutting that down), was that it would get stuck somewhere deep in requests trying to reopen the connection. That was a couple months ago; I never found out if it was a sufficient fix for bots in vivo. I'll see if I can dig up that code, and try it on a bot connected to a real instance to see if it's just a deficiency in my test setup.

It looks like this was worked around in Mastodon.py here: halcy/Mastodon.py@d0ae9dc

I've edited ananas.py in my virtualenvs to use the new param, I'll report back in a week if it works or not.

Seems to work! Or at least, none of my bots have died in the past week.

I'll make a PR.