SinisterRectus / Discordia

Discord API library written in Lua for the Luvit runtime environment
MIT License
688 stars 144 forks source link

Bot seems to silently fail when reconnecting #387

Open Aws0mee opened 1 year ago

Aws0mee commented 1 year ago

Just installed Discordia and Luvit recently to work on a bot, and I've been getting a strange issue. The bot will randomly go offline after a few hours and when I check the console I will see that discord requested a reconnection and the bot claims to have reconnected. However, the bot does not seem to have actually reconnected properly as it will not respond to any chat commands and appears offline in the member list.

Below are 2 examples of my console before my bot stopped responding entirely and went offline in the message list. image

image

Ta-noshii commented 1 year ago

Im not sure how to phrase this correctly, but its windows automatically freezing the command window after a bit Use a vps or similar instead to host your bot or try running it in its own service for it

Aws0mee commented 1 year ago

Im not sure how to phrase this correctly, but its windows automatically freezing the command window after a bit Use a vps or similar instead to host your bot or try running it in its own service for it

I'm not exactly sure what you're talking about. I tested to see if the script was still running and it seems like it was. I was still able to print stuff to my console locally, but the connection to discord was completely nonfunctional. Additionally, it doesn't seem to try and reconnect ever again after this bug happens meaning the bot will be completely down until I manually fix it. I added in a sort of improper fix of automatically running my script again if the bot doesn't get any commands for an hour, but this fix is suboptimal as all variables are obviously reset when the script is executed again. As for using hosting, I'm running the bot off my dedicated windows server, so I don't think using a vps would change anything at all and would only have worse performance.

Ta-noshii commented 1 year ago

Have you tried disabling QuickEdit mode?

Command Prompt > Properties > Options > Quickedit

Aws0mee commented 1 year ago

Have you tried disabling QuickEdit mode?

Command Prompt > Properties > Options > Quickedit

I can try, but I don't see how that would change anything in this case.

Ta-noshii commented 1 year ago

Did that fix it for you?

Aws0mee commented 1 year ago

Did that fix it for you?

It appears it did not work. I disabled QuickEdit mode and added a timer to print every 10 mins to make sure the bot is still running. Bot is still running, but does not respond to any command still and appears offline on discord. Something is certainly wrong with the connection as this always happens after the bot says it reconnected.

In the screenshot below the script is still running fine, but the bot appears offline on discord and does not respond to any commands. image

Lort533 commented 1 year ago

How about using WireShark to see if or when does it stop sending any data?

Aws0mee commented 1 year ago

How about using WireShark to see if or when does it stop sending any data?

I mean I could use wireshark, but I have the source for everything running I might as well just add debug prints at that point. However, I recall @SinisterRectus saying he knows what the issue might be so maybe he can help us here.

MeteorTheLizard commented 1 year ago

I've had a similar problem which is very rare. In the two years that I've been running 4 bots, this issue only happened 5 times. Discord requests a re-connection.. and nothing happens, the bot does not re-connect and the last line in the log is just that discord requested a re-connection. The bot eventually times out on discords end, appears offline, doesn't do anything anymore, but the script is still running. The script then has to be restarted manually to resolve this problem.

Lort533 commented 1 year ago

How about using WireShark to see if or when does it stop sending any data?

I mean I could use wireshark, but I have the source for everything running I might as well just add debug prints at that point. However, I recall @SinisterRectus saying he knows what the issue might be so maybe he can help us here.

I don't think that debug prints may fully help, I mean by using WireShark you are sure that Discordia does not do anything to reconnect.

Aws0mee commented 1 year ago

I've had a similar problem which is very rare. In the two years that I've been running 4 bots, this issue only happened 5 times. Discord requests a re-connection.. and nothing happens, the bot does not re-connect and the last line in the log is just that discord requested a re-connection. The bot eventually times out on discords end, appears offline, doesn't do anything anymore, but the script is still running. The script then has to be restarted manually to resolve this problem.

Sounds like my exact issue, would you happen to be running your bot on windows server too?

MeteorTheLizard commented 1 year ago

Sounds like my exact issue, would you happen to be running your bot on windows server too?

Debian, on a pi to be exact. It's very rare, and again, the last line in the log is the "discord requested a re-connection" thing. It seems to be different to your issue as yours claims it has established a connection while mine doesn't. If I had to make a guess, I'd say that when discord requests a re-connection, and your internet cuts out in that exact moment, the script gets confused, tries to establish a connection a few times, and then just gives up, and doesn't care about your internet working again at one point. My internet resets daily and the timestamps seem to match.

Lort533 commented 1 year ago

If it had connection related issues, it would show an error like EAI_AGAIN. Again, try using Wireshark to see if any type of connection is actually being made, I guess some parts of code may look good while making unexpected results.