python-a2s icon indicating copy to clipboard operation
python-a2s copied to clipboard

Strange a2s.exceptions.BufferExhaustedError

Open Nereg opened this issue 2 years ago • 3 comments

So recently while developing my app I encountered this error:

Traceback (most recent call last):
 ...
  File "/src/servers_updater/defaultA2S.py", line 26, in collect
    results = await asyncio.gather(*corutines)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/players.py", line 42, in aplayers
    return await request_async(address, timeout, encoding, PlayersProtocol)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/a2s_async.py", line 32, in request_async
    response = await request_async_impl(conn, encoding, a2s_proto)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/a2s_async.py", line 60, in request_async_impl
    challenge = reader.read_uint32()
                ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/byteio.py", line 60, in read_uint32
    return self.unpack_one("L")
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/byteio.py", line 40, in unpack_one
    values = self.unpack(fmt)
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/byteio.py", line 37, in unpack
    return struct.unpack(new_fmt, self.read(fmt_size))
                                  ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/a2s/byteio.py", line 24, in read
    raise BufferExhaustedError()
a2s.exceptions.BufferExhaustedError

Here is my code:

    async def collect(self, serverList: list) -> list:
        corutines: list = []
        for server in serverList:
            ...
            corutines.append(a2s.ainfo(ip))
            corutines.append(a2s.aplayers(ip)) # <- this is where it fails as I can see from traceback 
        results = await asyncio.gather(*corutines)
        return results

The server is up and is successfully queried by steam server browser (without player data) and by my other app (with player data). And I couldn't reproduce this on my dev machine (win 10, python 3.11.0). But I successfully reproduced in my docker container which is linux and python 3.11.1. I also captured traffic the container was making. And it doesn't respond after it received two challenge responses. Here is my capture of the traffic. (I removed the MAC addresses but payloads should be intact) Please let me know if you need more packets or the link had expired!

Nereg avatar Feb 25 '23 19:02 Nereg

What I found so far:

  1. It isn't specific to 3.11.1. It still gives that error on 3.10.0 on linux
  2. It also affects sync variants of aplayers
  3. It affects both variants of rules. I didn't use that in my app so I didn't catch it on initial discovery.
  4. This doesn't affect PyPi version! I used code directly from master to get typing working.

So I will write back when I narrow down where the regression was introduced.

Nereg avatar Feb 26 '23 16:02 Nereg

I've noticed this too when merging the typing PR, thank you for investigating! I'd recommend you don't use master until it's stable again. I'll move the changes to a new branch (https://github.com/Yepoleb/python-a2s/tree/typing) to make it less likely to accidentally use the broken version.

Yepoleb avatar Feb 27 '23 20:02 Yepoleb

Ok! Yeah I couldn't narrow down enough to see where this was introduced because of errors on each commit which I wouldn't want to fix in console lol. Good luck with typing though!

Nereg avatar Feb 28 '23 08:02 Nereg