gera2ld / async_dns

DNS library based on asyncio
MIT License
70 stars 17 forks source link

TCP - asyncio.exceptions.IncompleteReadError #31

Closed powellnorma closed 6 months ago

powellnorma commented 6 months ago

Any idea what the cause of this might be? Seems to happen randomly every now-and-then ..


[..]
    res, cached = await resolver.query(domain, record_type)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/base_resolver.py", line 64, in query
    return await asyncio.wait_for(self._query(fqdn, qtype),
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/tasks.py", line 489, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/util.py", line 23, in wrapped
    return await future
           ^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/proxy_resolver.py", line 92, in _query
    res = await self.request(fqdn, qtype, addr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/base_resolver.py", line 70, in request
    result = await self.client.query(fqdn, qtype, addr)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/client.py", line 35, in query
    return await task
           ^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/client.py", line 42, in _query
    res = await asyncio.wait_for(self._request(req, addr), self.timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/tasks.py", line 489, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/resolver/client.py", line 51, in _request
    data = await request(req, addr, self.timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/request/tcp.py", line 32, in request
    result = await asyncio.wait_for(_request(req, addr), timeout)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/tasks.py", line 489, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/async_dns/request/tcp.py", line 22, in _request
    size, = struct.unpack('!H', await reader.readexactly(2))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/streams.py", line 730, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes
gera2ld commented 6 months ago

I think it's just some random network issue and you just need to retry.

powellnorma commented 6 months ago

Maybe it would make sense if this "retry logic" gets added to the library? Normally TCP has "retry-logic" builtin, I think its weird this is happening (I used 1.1.1.1 as DNS Server)

gera2ld commented 6 months ago

Yes, reasonable since we already use a connection pool.