rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
125 stars 25 forks source link

httpx.ReadTimeout errors #78

Closed letmejustputthishere closed 1 year ago

letmejustputthishere commented 1 year ago

I'm getting a lot of httpx.ReadTimeout exceptions, is there anything that can be done to prevent this?

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 130, in _call_sslobject_method
    result = func(*args)
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/ssl.py", line 916, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2536)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 33, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 195, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 137, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
    await self._protocol.read_event.wait()
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 31, in read
    with anyio.fail_after(timeout):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py", line 105, in handle_async_request
    raise exc
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py", line 84, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py", line 148, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/http11.py", line 177, in _receive_event
    data = await self._network_stream.read(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 30, in read
    with map_exceptions(exc_map):
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 50, in verify_ownership_for_user
    tokens = await user_has_tokens(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 104, in user_has_tokens
    result = await icp_ledger.account_balance_async({'account' : account})  # type: ignore
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/canister.py", line 97, in __call__
    res = await self.agent.query_raw_async(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/agent.py", line 93, in query_raw_async
    result = await self.query_endpoint_async(canister_id if effective_canister_id is None else effective_canister_id, data)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/agent.py", line 46, in query_endpoint_async
    ret = await self.client.query_async(canister_id, data)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/client.py", line 37, in query_async
    ret = await client.post(endpoint, data = data, headers=headers)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1842, in post
    return await self.request(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout
2022-08-24 15:50:23 INFO     discord start
2022-08-24 15:50:28 ERROR    discord error checking ownership
Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 130, in _call_sslobject_method
    result = func(*args)
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/ssl.py", line 974, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 67, in start_tls
    ssl_stream = await anyio.streams.tls.TLSStream.wrap(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 122, in wrap
    await wrapper._call_sslobject_method(ssl_object.do_handshake)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/streams/tls.py", line 137, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
    await self._protocol.read_event.wait()
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 76, in start_tls
    raise exc
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 66, in start_tls
    with anyio.fail_after(timeout):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
    raise exc
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_async/connection.py", line 150, in _connect
    stream = await stream.start_tls(**kwargs)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 64, in start_tls
    with map_exceptions(exc_map):
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 50, in verify_ownership_for_user
    tokens = await user_has_tokens(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/glue/discord_bot/helpers.py", line 104, in user_has_tokens
    result = await icp_ledger.account_balance_async({'account' : account})  # type: ignore
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/canister.py", line 97, in __call__
    res = await self.agent.query_raw_async(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/agent.py", line 93, in query_raw_async
    result = await self.query_endpoint_async(canister_id if effective_canister_id is None else effective_canister_id, data)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/agent.py", line 46, in query_endpoint_async
    ret = await self.client.query_async(canister_id, data)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/ic/client.py", line 37, in query_async
    ret = await client.post(endpoint, data = data, headers=headers)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1842, in post
    return await self.request(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/Users/moritz/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/moritz/projects/ic/glue-org/glue-bot/.venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectTimeout
Myse1f commented 1 year ago

set timeout to None in #83