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

Implement WebSocket connection backend #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

njbooher
Copy link

@njbooher njbooher commented Sep 5, 2024

Resolves #114

@njbooher njbooher marked this pull request as ready for review September 9, 2024 00:11
@denizkoekden
Copy link

denizkoekden commented Oct 12, 2024

I just wanted to throw my support behind this PR. I’m currently using @njboohers' wsproto branch by manually importing it, and it’s been working great for me. This library is used in a lot of Steam Python projects, many of which have stopped working due to the current connection method breaking down.

It would be awesome to see this merged ASAP since it fixes the issue and gets everything back on track. Big thanks to everyone involved in pushing this forward! Maybe @rossengeorgiev can help out here?

@njbooher
Copy link
Author

IIRC, during my testing, the main issue I encountered was connections to some servers didn't work, and I think it might have been due to them sending messages larger than the 16kb this reads at the time. I can't do any work on this this week, but possibly next week.

@denizkoekden
Copy link

IIRC, during my testing, the main issue I encountered was connections to some servers didn't work, and I think it might have been due to them sending messages larger than the 16kb this reads at the time. I can't do any work on this this week, but possibly next week.

I am using your fork in my productive Environment I have seen some errors in the log when connected to ams1 CM but they resolve after restarting the application. I will provide Logs with all the errors so we can resolve the Issues. ATM I am testing the fixes from @revij and @BlankTMing (denizkoekden@bee32ca).

@denizkoekden
Copy link

denizkoekden commented Oct 14, 2024

Okay I use denizkoekden@bee32ca which is your (@njbooher) Fork + the changes @revij and @BlankTMing did. The errors seem to be exactly the same as without their fixes. I was just some trial and error nobrainer testing as the base functionallity is given it just takes a few more tries to get the desired result. I use the steam lib in the steamcmd-project which is basically an simple but helpful FastAPI Project to retrive informations about an given appid.

Here are the last 100 lines of the log:

level=INFO msg="Requested app info" app_id=2667530
level=INFO msg="App info succesfully retrieved from cache" app_id=2667530
level=INFO msg="Succesfully retrieved app info" app_id=2667530
level=INFO msg="Requested app info" app_id=1794810
level=INFO msg="App info could not be found in cache" app_id=1794810
level=INFO msg="Started requesting app info" app_id=1794810
level=INFO msg="Retrieving app info from steamclient" app_id=1794810 retry_count=0
level=INFO msg="Succesfully retrieved app info" app_id=2667530
level=INFO msg="Succesfully retrieved app info" app_id=1794810
level=INFO msg="Requested app info" app_id=349090
level=INFO msg="App info could not be found in cache" app_id=349090
level=INFO msg="Started requesting app info" app_id=349090
level=INFO msg="Retrieving app info from steamclient" app_id=349090 retry_count=0
level=INFO msg="Requested app info" app_id=1794810
level=INFO msg="App info succesfully retrieved from cache" app_id=1794810
level=INFO msg="Succesfully retrieved app info" app_id=1794810
level=INFO msg="Succesfully retrieved app info" app_id=1794810
level=INFO msg="Requested app info" app_id=349090
level=INFO msg="App info could not be found in cache" app_id=349090
level=INFO msg="Started requesting app info" app_id=349090
level=INFO msg="Retrieving app info from steamclient" app_id=349090 retry_count=0
level=INFO msg="Requested app info" app_id=349090
level=INFO msg="App info could not be found in cache" app_id=349090
level=INFO msg="Started requesting app info" app_id=349090
level=INFO msg="Retrieving app info from steamclient" app_id=349090 retry_count=0
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.10/site-packages/steam/core/connection.py", line 216, in _reader_loop
    rlist, _, _ = gselect([self.socket], [], [])
  File "/usr/local/lib/python3.10/site-packages/gevent/select.py", line 181, in select
    sel_results = _original_select(rlist, wlist, xlist, 0)
ValueError: filedescriptor out of range in select()
2024-10-14T12:52:49Z <Greenlet at 0x7f3660773380: <bound method WebsocketConnection._reader_loop of <steam.core.connection.WebsocketConnection object at 0x7f3660798340>>> failed with ValueError

level=INFO msg="Succesfully retrieved app info" app_id=349090
level=INFO msg="Requested app info" app_id=2515600
level=INFO msg="App info could not be found in cache" app_id=2515600
level=INFO msg="Started requesting app info" app_id=2515600
level=INFO msg="Retrieving app info from steamclient" app_id=2515600 retry_count=0
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.10/site-packages/steam/core/connection.py", line 216, in _reader_loop
    rlist, _, _ = gselect([self.socket], [], [])
  File "/usr/local/lib/python3.10/site-packages/gevent/select.py", line 181, in select
    sel_results = _original_select(rlist, wlist, xlist, 0)
ValueError: filedescriptor out of range in select()
2024-10-14T12:52:50Z <Greenlet at 0x7f3649624c20: <bound method WebsocketConnection._reader_loop of <steam.core.connection.WebsocketConnection object at 0x7f366436fd60>>> failed with ValueError

level=INFO msg="Succesfully retrieved app info" app_id=349090
level=INFO msg="Requested app info" app_id=2515600
level=INFO msg="App info could not be found in cache" app_id=2515600
level=INFO msg="Started requesting app info" app_id=2515600
level=INFO msg="Retrieving app info from steamclient" app_id=2515600 retry_count=0
level=WARNING msg="Encountered timeout when trying to connect to steam api. Retrying.."
level=ERROR msg="Max connect retries exceeded" connect_retries=2
level=ERROR msg="Failed in retrieving app info" app_id=2394010
level=ERROR msg="Max connect retries (2) exceeded" app_id=2394010
level=INFO msg="The SteamCMD backend returned no actual data and failed" app_id=2394010
level=INFO msg="Requested app info" app_id=2394010
level=INFO msg="App info could not be found in cache" app_id=2394010
level=INFO msg="Started requesting app info" app_id=2394010
level=INFO msg="Retrieving app info from steamclient" app_id=2394010 retry_count=0
level=INFO msg="Succesfully retrieved app info" app_id=2515600
level=INFO msg="Requested app info" app_id=2533070
level=INFO msg="App info could not be found in cache" app_id=2533070
level=INFO msg="Started requesting app info" app_id=2533070
level=INFO msg="Retrieving app info from steamclient" app_id=2533070 retry_count=0
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.10/site-packages/steam/core/connection.py", line 216, in _reader_loop
    rlist, _, _ = gselect([self.socket], [], [])
  File "/usr/local/lib/python3.10/site-packages/gevent/select.py", line 181, in select
    sel_results = _original_select(rlist, wlist, xlist, 0)
ValueError: filedescriptor out of range in select()
2024-10-14T12:52:51Z <Greenlet at 0x7f36607734c0: <bound method WebsocketConnection._reader_loop of <steam.core.connection.WebsocketConnection object at 0x7f366088f0d0>>> failed with ValueError

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.10/site-packages/steam/client/__init__.py", line 101, in _parse_message
    result = CMClient._parse_message(self, message)
  File "/usr/local/lib/python3.10/site-packages/steam/core/cm.py", line 289, in _parse_message
    msg.parse()
  File "/usr/local/lib/python3.10/site-packages/steam/core/msg/__init__.py", line 201, in parse
    self.body.ParseFromString(self.payload)
google.protobuf.message.DecodeError: Error parsing message with type 'CMsgMulti'
2024-10-14T12:52:51Z <Greenlet at 0x7f3660a43420: <bound method SteamClient._parse_message of <SteamClient(('cmp2-ams1.steamserver.net', 27018)) online>>(bytearray(b'\x01\x00\x00\x80\x00\x00\x00\x00\x08\x)> failed with DecodeError

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.10/site-packages/steam/client/__init__.py", line 101, in _parse_message
    result = CMClient._parse_message(self, message)
  File "/usr/local/lib/python3.10/site-packages/steam/core/cm.py", line 259, in _parse_message
    emsg = EMsg(clear_proto_bit(emsg_id))
  File "/usr/local/lib/python3.10/enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.10/enum.py", line 710, in __new__
    raise ve_exc
ValueError: 1003589537 is not a valid EMsg
2024-10-14T12:52:51Z <Greenlet at 0x7f3660a43420: <bound method SteamClient._parse_message of <SteamClient(('cmp2-ams1.steamserver.net', 27018)) online>>(bytearray(b'\xa1\x8f\xd1\xbb\xdc\xda\x1be\xee\x19\)> failed with ValueError

@BlankTMing
Copy link

Use TCPConnection instead of WebSocket @denizkoekden

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

Successfully merging this pull request may close these issues.

Implement WebSocket connection backend
3 participants