fief-dev / fief

Users and authentication management SaaS
https://www.fief.dev
Other
486 stars 42 forks source link

500 Internal Server Error - httpx.ReadTimeout #281

Closed QnalNandi closed 8 months ago

QnalNandi commented 9 months ago

Randomly facing httpx.ReadTimeout after keeping the logged in user idle for long time

Seems like fief_client fails to get the userinfo

2023-09-20T08:43:22.277429221Z   File "<makefun-gen-21>", line 2, in _current_user
2023-09-20T08:43:22.277438522Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/integrations/fastapi.py", line 240, in _current_user
2023-09-20T08:43:22.277443322Z     userinfo = cast(FiefUserInfo, await result)
2023-09-20T08:43:22.277447722Z                                   ^^^^^^^^^^^^
2023-09-20T08:43:22.277452223Z   File "/usr/lib/python3.11/contextlib.py", line 222, in __aexit__
2023-09-20T08:43:22.277456923Z     await self.gen.athrow(typ, value, traceback)
2023-09-20T08:43:22.277461423Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/client.py", line 988, in _get_httpx_client
2023-09-20T08:43:22.277466024Z     yield client
2023-09-20T08:43:22.277470524Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/client.py", line 912, in userinfo
2023-09-20T08:43:22.277475224Z     response = await client.send(request)

To Reproduce

Steps to reproduce the behavior:

Expected behavior

No crash

Configuration

Additional context

Adding the whole logs

2023-09-20T08:43:22.276834581Z ERROR:    Exception in ASGI application
2023-09-20T08:43:22.276868184Z Traceback (most recent call last):
2023-09-20T08:43:22.276875784Z   File "/usr/local/lib/python3.11/dist-packages/anyio/streams/tls.py", line 131, in _call_sslobject_method
2023-09-20T08:43:22.276881684Z     result = func(*args)
2023-09-20T08:43:22.276887085Z              ^^^^^^^^^^^
2023-09-20T08:43:22.276892485Z   File "/usr/lib/python3.11/ssl.py", line 921, in read
2023-09-20T08:43:22.276898086Z     v = self._sslobj.read(len)
2023-09-20T08:43:22.276903486Z         ^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.276908886Z ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2546)
2023-09-20T08:43:22.276914387Z
2023-09-20T08:43:22.276919587Z During handling of the above exception, another exception occurred:
2023-09-20T08:43:22.276925087Z
2023-09-20T08:43:22.276930288Z Traceback (most recent call last):
2023-09-20T08:43:22.276935688Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_backends/anyio.py", line 34, in read
2023-09-20T08:43:22.276940588Z     return await self._stream.receive(max_bytes=max_bytes)
2023-09-20T08:43:22.276945689Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.276951089Z   File "/usr/local/lib/python3.11/dist-packages/anyio/streams/tls.py", line 196, in receive
2023-09-20T08:43:22.276956589Z     data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
2023-09-20T08:43:22.276962090Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.276978791Z   File "/usr/local/lib/python3.11/dist-packages/anyio/streams/tls.py", line 138, in _call_sslobject_method
2023-09-20T08:43:22.276984591Z     data = await self.transport_stream.receive()
2023-09-20T08:43:22.276989992Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.276995092Z   File "/usr/local/lib/python3.11/dist-packages/anyio/_backends/_asyncio.py", line 1203, in receive
2023-09-20T08:43:22.277000692Z     await self._protocol.read_event.wait()
2023-09-20T08:43:22.277006093Z   File "/usr/lib/python3.11/asyncio/locks.py", line 213, in wait
2023-09-20T08:43:22.277011693Z     await fut
2023-09-20T08:43:22.277016894Z asyncio.exceptions.CancelledError
2023-09-20T08:43:22.277022194Z
2023-09-20T08:43:22.277027394Z During handling of the above exception, another exception occurred:
2023-09-20T08:43:22.277032895Z
2023-09-20T08:43:22.277037495Z Traceback (most recent call last):
2023-09-20T08:43:22.277042795Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_exceptions.py", line 10, in map_exceptions
2023-09-20T08:43:22.277048296Z     yield
2023-09-20T08:43:22.277053196Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_backends/anyio.py", line 32, in read
2023-09-20T08:43:22.277058196Z     with anyio.fail_after(timeout):
2023-09-20T08:43:22.277062997Z   File "/usr/local/lib/python3.11/dist-packages/anyio/_core/_tasks.py", line 119, in __exit__
2023-09-20T08:43:22.277067797Z     raise TimeoutError
2023-09-20T08:43:22.277072397Z TimeoutError
2023-09-20T08:43:22.277076898Z
2023-09-20T08:43:22.277081398Z The above exception was the direct cause of the following exception:
2023-09-20T08:43:22.277086098Z
2023-09-20T08:43:22.277090598Z Traceback (most recent call last):
2023-09-20T08:43:22.277096499Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
2023-09-20T08:43:22.277101399Z     yield
2023-09-20T08:43:22.277106000Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_transports/default.py", line 353, in handle_async_request
2023-09-20T08:43:22.277111000Z     resp = await self._pool.handle_async_request(req)
2023-09-20T08:43:22.277115700Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277120400Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request
2023-09-20T08:43:22.277125201Z     raise exc
2023-09-20T08:43:22.277129801Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request
2023-09-20T08:43:22.277134701Z     response = await connection.handle_async_request(request)
2023-09-20T08:43:22.277139402Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277148902Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/connection.py", line 96, in handle_async_request
2023-09-20T08:43:22.277153903Z     return await self._connection.handle_async_request(request)
2023-09-20T08:43:22.277158603Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277163203Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/http11.py", line 121, in handle_async_request
2023-09-20T08:43:22.277168004Z     raise exc
2023-09-20T08:43:22.277172404Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/http11.py", line 99, in handle_async_request
2023-09-20T08:43:22.277177404Z     ) = await self._receive_response_headers(**kwargs)
2023-09-20T08:43:22.277182005Z         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277186405Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/http11.py", line 164, in _receive_response_headers
2023-09-20T08:43:22.277191105Z     event = await self._receive_event(timeout=timeout)
2023-09-20T08:43:22.277195706Z             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277200106Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_async/http11.py", line 200, in _receive_event
2023-09-20T08:43:22.277204906Z     data = await self._network_stream.read(
2023-09-20T08:43:22.277209506Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277214207Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_backends/anyio.py", line 31, in read
2023-09-20T08:43:22.277218907Z     with map_exceptions(exc_map):
2023-09-20T08:43:22.277223407Z   File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
2023-09-20T08:43:22.277228008Z     self.gen.throw(typ, value, traceback)
2023-09-20T08:43:22.277232608Z   File "/usr/local/lib/python3.11/dist-packages/httpcore/_exceptions.py", line 14, in map_exceptions
2023-09-20T08:43:22.277237708Z     raise to_exc(exc) from exc
2023-09-20T08:43:22.277242209Z httpcore.ReadTimeout
2023-09-20T08:43:22.277246609Z
2023-09-20T08:43:22.277251109Z The above exception was the direct cause of the following exception:
2023-09-20T08:43:22.277255710Z
2023-09-20T08:43:22.277260110Z Traceback (most recent call last):
2023-09-20T08:43:22.277264510Z   File "/usr/local/lib/python3.11/dist-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
2023-09-20T08:43:22.277269310Z     result = await app(  # type: ignore[func-returns-value]
2023-09-20T08:43:22.277273911Z              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277278311Z   File "/usr/local/lib/python3.11/dist-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
2023-09-20T08:43:22.277283011Z     return await self.app(scope, receive, send)
2023-09-20T08:43:22.277291412Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277296112Z   File "/usr/local/lib/python3.11/dist-packages/fastapi/applications.py", line 292, in __call__
2023-09-20T08:43:22.277300813Z     await super().__call__(scope, receive, send)
2023-09-20T08:43:22.277305413Z   File "/usr/local/lib/python3.11/dist-packages/starlette/applications.py", line 122, in __call__
2023-09-20T08:43:22.277310113Z     await self.middleware_stack(scope, receive, send)
2023-09-20T08:43:22.277314614Z   File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/errors.py", line 184, in __call__
2023-09-20T08:43:22.277319214Z     raise exc
2023-09-20T08:43:22.277323614Z   File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/errors.py", line 162, in __call__
2023-09-20T08:43:22.277328414Z     await self.app(scope, receive, _send)
2023-09-20T08:43:22.277332815Z   File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/exceptions.py", line 79, in __call__
2023-09-20T08:43:22.277337515Z     raise exc
2023-09-20T08:43:22.277341815Z   File "/usr/local/lib/python3.11/dist-packages/starlette/middleware/exceptions.py", line 68, in __call__
2023-09-20T08:43:22.277346516Z     await self.app(scope, receive, sender)
2023-09-20T08:43:22.277351016Z   File "/usr/local/lib/python3.11/dist-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
2023-09-20T08:43:22.277355716Z     raise e
2023-09-20T08:43:22.277360117Z   File "/usr/local/lib/python3.11/dist-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
2023-09-20T08:43:22.277364817Z     await self.app(scope, receive, send)
2023-09-20T08:43:22.277369317Z   File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 718, in __call__
2023-09-20T08:43:22.277373918Z     await route.handle(scope, receive, send)
2023-09-20T08:43:22.277378518Z   File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 276, in handle
2023-09-20T08:43:22.277383218Z     await self.app(scope, receive, send)
2023-09-20T08:43:22.277387718Z   File "/usr/local/lib/python3.11/dist-packages/starlette/routing.py", line 66, in app
2023-09-20T08:43:22.277392719Z     response = await func(request)
2023-09-20T08:43:22.277397219Z                ^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277401719Z   File "/usr/local/lib/python3.11/dist-packages/fastapi/routing.py", line 263, in app
2023-09-20T08:43:22.277406420Z     solved_result = await solve_dependencies(
2023-09-20T08:43:22.277410920Z                     ^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277415420Z   File "/usr/local/lib/python3.11/dist-packages/fastapi/dependencies/utils.py", line 584, in solve_dependencies
2023-09-20T08:43:22.277420221Z     solved = await call(**sub_values)
2023-09-20T08:43:22.277424721Z              ^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277429221Z   File "<makefun-gen-21>", line 2, in _current_user
2023-09-20T08:43:22.277438522Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/integrations/fastapi.py", line 240, in _current_user
2023-09-20T08:43:22.277443322Z     userinfo = cast(FiefUserInfo, await result)
2023-09-20T08:43:22.277447722Z                                   ^^^^^^^^^^^^
2023-09-20T08:43:22.277452223Z   File "/usr/lib/python3.11/contextlib.py", line 222, in __aexit__
2023-09-20T08:43:22.277456923Z     await self.gen.athrow(typ, value, traceback)
2023-09-20T08:43:22.277461423Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/client.py", line 988, in _get_httpx_client
2023-09-20T08:43:22.277466024Z     yield client
2023-09-20T08:43:22.277470524Z   File "/usr/local/lib/python3.11/dist-packages/fief_client/client.py", line 912, in userinfo
2023-09-20T08:43:22.277475224Z     response = await client.send(request)
2023-09-20T08:43:22.277479825Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.277486425Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 1617, in send
2023-09-20T08:43:22.283676341Z     response = await self._send_handling_auth(
2023-09-20T08:43:22.283683341Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.283688542Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 1645, in _send_handling_auth
2023-09-20T08:43:22.283693642Z     response = await self._send_handling_redirects(
2023-09-20T08:43:22.283698542Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.283703242Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 1682, in _send_handling_redirects
2023-09-20T08:43:22.283708143Z     response = await self._send_single_request(request)
2023-09-20T08:43:22.283720944Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.283725744Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_client.py", line 1719, in _send_single_request
2023-09-20T08:43:22.283730644Z     response = await transport.handle_async_request(request)
2023-09-20T08:43:22.283735345Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-09-20T08:43:22.283740145Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_transports/default.py", line 352, in handle_async_request
2023-09-20T08:43:22.283748046Z     with map_httpcore_exceptions():
2023-09-20T08:43:22.283752746Z   File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
2023-09-20T08:43:22.283757446Z     self.gen.throw(typ, value, traceback)
2023-09-20T08:43:22.283762046Z   File "/usr/local/lib/python3.11/dist-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
2023-09-20T08:43:22.283766847Z     raise mapped_exc(message) from exc
2023-09-20T08:43:22.283771547Z httpx.ReadTimeout
frankie567 commented 9 months ago

It might be possible the Fief cloud server takes a long time to respond. Where are you geographically located? Did you setup your own database (if so, where it's geographically locaoted?) or did you used the cloud database?