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

Websocket closed after some time #65

Closed
rb1997 opened this issue May 5, 2021 · 8 comments
Closed

Websocket closed after some time #65

rb1997 opened this issue May 5, 2021 · 8 comments

Comments

@rb1997
Copy link

rb1997 commented May 5, 2021

When running the script for a few hours, the log says websocket closed and the script exits. What could be causing this and is there a known solution?

Thanks!


arandomnewaccount:
did you install from pypi or from the github repo?

@rb1997
Copy link
Author

rb1997 commented May 5, 2021

installed using pip / pypi


arandomnewaccount:
ah ok. The pypi is 2 versions behind the github. So, just uninstall the pypi version (pip uninstall discum) and install directly from the github repo (python -m pip install --user --upgrade git+https://github.com/Merubokkusu/Discord-S.C.U.M.git)

@rb1997
Copy link
Author

rb1997 commented May 5, 2021

Thanks, just reinstalled using git, will see how it goes :)

@hungrybeagle
Copy link

hungrybeagle commented May 6, 2021

I am having the same issue... socket seems to close in under an hour. I upgraded to 1.2.1 but no better


arandomnewaccount:
under an hour? That's new. Which python version are you using?

@akbar-amin
Copy link
Contributor

akbar-amin commented May 7, 2021

It may be due to this not being handled correctly:

The gateway may request a heartbeat from the client in some situations by sending an Opcode 1 Heartbeat. When this occurs, the client should immediately send an Opcode 1 Heartbeat without waiting the remainder of the current interval.

This is from the heartbeat section in the developer docs.

I don't recall seeing this in the documentation before, but I may be wrong. Nothing in the changelog hints it was added. In any case, if the gateway is sending more than one "HELLO" event, the handling for it needs to be reworked so that it doesn't collide with the current heartbeat thread.


arandomnewaccount:
hm. Well I'm still getting the feeling that @hungrybeagle 's disconnects are not related to heartbeats since the current reconnection implementation in discum reconnects unless the user does bot.gateway.close() or ctrl-c. So, even if the dev/user were to send a wrongly formatted msg to the gateway (which would cause discord to close the connection), discum would still reconnect. So, @hungrybeagle, could send the log and any errors you got (don't forget to remove your token from the logs)?

However, it's still important that you, @akbar-amin, bring that up.
Interestingly, I don't recall seeing any opcode 1s coming from discord (neither in my discum tests nor in the official client).
Anyway, It shouldn't be too tricky to implement a handler for this into discum, so long as it is independent of the current heartbeat thread.

Also, multiple hello events would be.....weird. But eh ig anythings possible with discord's weird api. I'll be on the lookout for
"duplicate" HELLO events.

On a side note, I know that gateway reconnections should depend on close codes. The reason they haven't for discum so far is because websocket-client was not sending back any close codes. This seemed to have changed yesterday (websocket-client/websocket-client#686), so I'll be doing some tests and hopefully, finally, making the reconnection handling mimic the official client.
pushed a few updates, next push will include close codes among other updates

@hungrybeagle
Copy link

hungrybeagle commented May 7, 2021

Running Python 3.8.5

Not sure if this is what you're looking for... log set to Trueimage

I don't have it trying to close or anything, I'm just using it to read all messages as they come up, filter the ones from specific categories and forward them to a telegram so I can see them all in one place. I've worked around it by just placing the whole program in a while True loop so that as soon as it disconnects, it reinitializes the client and continues on


arandomnewaccount:
huh, that's weird, you shouldn't have to put it in a while loop. Here, it might be easier to debug this if we chat. You can email me at discordtehe@gmail.com and we can continue from there.
And then, after we figure out what's going on, I'll write here what the issue was so other ppl can see it too.

@vivinano
Copy link
Contributor

vivinano commented May 11, 2021

I believe my app is also breaking when this happens so as soon as the websocket closes then im suck in a infinite send loop

image


arandomnewaccount:
gonna run a test for a day and see if I can replicate those results on my end.
Btw (1) which python version are you running and (2) what discum version are you using?

@vivinano
Copy link
Contributor

vivinano commented May 12, 2021

Python 3.8.5 and disum 1.2.1


arandomnewaccount:
alr, thx. Made some changes to gateway.py so either reinstall or copy-paste the new gateway.py file into your installation location. I'll keep running it on my end but it seems to have fixed the error. Let me know if you run into any problems.

@vivinano
Copy link
Contributor

vivinano commented May 14, 2021

Been running my selfbot for 24 hours I think the issue has been fixed with the changes to gateway.py


nice ok. I've also been running bot.gateway.run() on my end for the past ~1.5 days and it's been running smoothly.

edit: still running a version on my end and it's been running smoothly. I'll be closing this issue - feel free to open up another one if gateway reconnection issues arise when using the most up-to-date version of discum.

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

No branches or pull requests

5 participants
@rb1997 @vivinano @hungrybeagle @akbar-amin and others