-
Notifications
You must be signed in to change notification settings - Fork 411
Hermes WebSocket API (Fixes #722) #728
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
base: master
Are you sure you want to change the base?
Conversation
Implements a WebSocket client and pool for the Hermes API. Abstracts some of the handling for PubSub Messages. Adds the "use_hermes" Setting to allow the use of the Hermes WebSocket API instead of the PubSub WebSocket API. Defaults to False. Renamed WebSocket classes and moved them to new websocket module.
|
Have been using it for around 48+ hours and only encountered "websocket closed None : None error" and "websocket error 104 connection closed by peer " error otherwise all features of the code are working perfectly fine ( excluding betting and drops which are still yet to test) |
Hey, thanks for your help! The The other message is probably fine. 104s can happen for a number of reasons but if it's reconnecting without issues I wouldn't worry about it. |
|
For the None : None errors I just looked into another of my Miner which is on pubserver and noticed that actually the twitch servers was having some errors as both of the miners (one on hermes and one on pubserver) were disconnected at the same time which means that it isn't actually any code issue |
|
how to download? |
You can clone my branch here. No automated builds for this one since it's not an official release. |
I have a question: If I upload this to rander.com after I've linked it to my Twitch account, why does it ask me to link it again if I've already linked it? |
Sorry, I have no idea. |
|
If I modify this part, will it work the same way? |
|
Please try to use chatgpt for code modifying questions or just open a discussion or issue in the main repo. Also do read the readme file thoroughly it explains everything. |
|
Update: There might be an issue somewhere related to betting cuz some of the best are getting logged twice that means maybe they are being processed twice (there might be a chance that the streamer actually made 2 different predictions back to back not sure though but still thought to drop my observations here) |
Yeah, that looks like 2 different predictions with the same name happening close together. Might be worth checking the stream to see if it happens again. |
|
I checked the stream and the predictions were actually made so not any issue about that. But the disconnections are a lot frequent as compared to pubsub like i disconnected 7-8 times in a 12 hours run and the most frequent was on a gap of like 35-40 mins only |
I've seen an increase in reconnects too, not to the same degree but then I only run with a single client in the pool. I think this is something they've built into the new API to better distribute server load but no way to know for sure. As long as it reconnects without issue there should be no problem. For that 35-40 min gap, were the disconnections from something like a timeout or were they from a For reference, the where the |
You can set the file logs to
Looks like an unrelated error, a quick issue search doesn't find that anywhere so if it happens again while using the regular miner release you should open an issue about it. |
|
I don't use that too cuz my vps doesn't have root access 🤦🏻♂️😂 |
I've actually already considered, at least the accurate parts, of this and I'm not sure it's necessary to respect the keepalive timeout. It feels unnecessary to close the connection early when keepalives aren't being sent in a timely manner when it could just be server congestion. Saying this, I will give you that the Twitch Web client does seem to implement something like this so maybe it would be for the best. The bit about "initiate the keep-alive" cycle is wrong, the server is responsible for sending keepalives. All the client has to do is connect, authenticate, and subscribe. The old PubSub API used a The more frequent disconnections might just be how this API is going to be. As long as the miner is able to reconnect, does it really matter if it's disconnecting more often? I might try and hide some of the log messages if the client is told by Twitch to reconnect, it's not a case the user should worry about. |
|
That's a weird one, never seen it log the frame as an error before. From what I can tell Also, can you say where |
|
As of now these are the only logs related to disconnections but I'll switch to debug logging and will get more info about the same |
|
@Gamerns10s I'm sorry but without the full stack trace for the error I can't pinpoint where it's coming from. Is there any chance you could run it on a machine where you have access to the log files? I would also need |
|
In that case I can run it on termux but it'll take some time to get the logs but I'll surely try to share it asap |
|
@mpforce1 do you have any other social media or email address where I can share you the logs file |
No, sorry. The last time this happened the user uploaded them to proton storage and posted a link here. Once I'd confirmed download they deleted the files. You could try something like that. |
|
I think at one point my device lost internet connection you can ignore that disconnection 😅 |
Any chance you could post your log file for this? I'd need |
|
here you go |
|
@OlevO1 Weirdly, you seem to somehow have my latest commit which better respects the keepalive messages but you don't have the 2 other ones I pushed up. I can tell this because I see it logging |
|
Alright reinstalled everything. It’s better now. |
Seems to be, enough people have confirmed frequent reconnections that it looks like Twitch has built it into the API. I'll do a little more investigation and see if it's something I can do anything about. |
okay, ty |
|
It was on Less=True, but I don’t get what’s wrong again |
|
@OlevO1 I think I see what's happened here. First it's timed out for this |
…nitialised client is closed and then opened. Adds a timeout (of 5 minutes) for a client to wait for initialisation. Adds the client id to log messages, unless less is True.
|
@OlevO1 I've pushed up a new version that should fix that dangling client issue. Let me know if it keeps happening. If you run into that logging.getLogger("chardet.charsetprober").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
logging.getLogger("werkzeug").setLevel(logging.ERROR)
logging.getLogger("irc.client").setLevel(logging.ERROR)
logging.getLogger("seleniumwire").setLevel(logging.ERROR)
logging.getLogger("websocket").setLevel(logging.ERROR)to import websocket
logging.getLogger("chardet.charsetprober").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
logging.getLogger("werkzeug").setLevel(logging.ERROR)
logging.getLogger("irc.client").setLevel(logging.ERROR)
logging.getLogger("seleniumwire").setLevel(logging.ERROR)
logging.getLogger("websocket").setLevel(logging.DEBUG)
websocket.enableTrace(True)This sets the |
I'm sorry but I can't find |
|
I'm using the latest version with the Hermes API implementation (PR #728), but I'm still experiencing an issue where the bot only collects points from one streamer at a time, even when multiple streamers I'm following are live simultaneously. The bot appears to connect to multiple streams based on logs, but points are only accruing for one streamer. This seems to be a limitation with how Twitch recognizes 'active viewing' rather than an issue with the Hermes API implementation itself. Is there any way to modify the script to rotate between streamers more frequently or to somehow enable simultaneous point collection from multiple streams? |
nvm, works for me now thanks |
It should collect from 2 streamers at once. You might be experiencing the same issue as #722 (comment) where the same channel was filling both of the miner's slots. If you want you can try to apply the fix I posted in that comment. I'm not sure how successful the fix was because I haven't heard back from the user yet. |
Im gonna apply that fix and run script for like 30 minutes and tell u if it worked is that okay? |
|
@mpforce1 So i ran it for a while and its working good no problem im also using my modified version of script but fused with your latest commit here and have no issues. |
Ah my bad, forgot about that. Been working fine since, not sure if it was that fix or me removing kai from run.py so it only loads him from rest of the followed channels, most likely the fix though. Haven't really noticed any issues other than the reconnects every 5-40 minutes but it's not getting hung up or stopped. Seems pretty random when and how often it happens. |
|
I indeed had a unreleased version of websocket ( I didn't even knew that lol) but now I fixed it and here are my logs with the latest changes to this pr |
Hey, thanks for that. I can see you're having an issue I noticed in my own logs last night. This |
|
Just noticed that for me after the recent changes the disconnections have actually increased like in a 6 hr run I got disconnected 16 times ( 9 times in an hour and most frequent was at an interval of 4 mins only ) |
Yeah, that's almost certainly this stale connection detection bug. My new change a) fixes this issue b) improves resources usage by removing a It ran fine for me last night with no stale connections, no errors, and 2 |
… message flow. Keepalive timeout is now a message timeout to avoid scenarios where the server doesn't send a keepalive because it's sent a message. Fixed issue where newly opened clients could be considered stale if the stale check happens at the right time. Removed client thread that checks for pending subscriptions as we only subscribe once at startup. Changed INFO logs to DEBUG for hermes, ERROR/WARNING should be all users need.
|
I've finished testing the new change, this should fix the client reconnecting all the time. The issue was twofold:
I also had a look at the Twitch web client again and tried to better match their message flow. Now the client starts Thanks again to everyone who's participating, you're helping us get closer to a stable implementation. Please test this new version and let me know if you have any issues. |
That's actually the same error as before, the
I think I've seen somebody else complain about that one, might be worth doing a search. That message format |
|
Been pretty solid since that last update, no issues on this end. |
|
@Gamerns10s It's hard to tell what's going on because of how you've formatted the logs. To get a better idea I'd need text from the log file or an upload of the log file. However, from what I can see it looks like you might have a poor connection between you and the Twitch servers. I still have no idea what the |
|
Yeah I can totally understand that and will try to share the logs file soon |
Sorry, I don't know much about the drops system. I'd like to keep this pr more on topic, please start a separate discussion/issue if you want help with something else. |














Description
Implements an integration with the new Hermes API. As per issue #722 it seems like Twitch has finally finished A/B testing the new Hermes API. This PR adds a new WebSocket based integration with this API. It acts as a drop in replacement for the older PubSub WebSocket integration.
As part of the implementation some of the handling of PubSub Messages has been abstracted. This was done to avoid duplicating the handling logic in both integrations.
I've added a new setting to the miner constructor
use_hermes. It defaults toFalsefor now to avoid changing current behaviour for most users. In the future this might be removed if Twitch drops the old PubSub API.I've opened this PR as draft as I'm currently seeing how it acts in the long term. This is because the reconnection logic in the new integration is different and I want to make sure it works as designed. To that end, it'd be really useful if some other community members could try out this branch and see if they run into any issues. In particular, I'd like to know:
user_hermestoFalseor omitting it from the configuration.I've tested all of this locally but more users testing in more varied setups should help catch any edge cases.
Fixes #722
Type of change
How Has This Been Tested?
Tested on my local setup. I'm currently running a long running test to check reconnection logic. However, my test setup only connects to a few streamers.
Checklist: