supertokens / supertokens-python

Python SDK for SuperTokens
https://supertokens.com
Other
129 stars 38 forks source link

Tenant creation request times out #516

Closed ocervell closed 3 months ago

ocervell commented 3 months ago

The request for creating a tenant currently times out for me (running Supertoken as a managed instance) because it takes more than 2 seconds to return the response from the API:

Traceback (most recent call last):
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 67, in map_httpcore_exceptions
    yield
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 371, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 216, in handle_async_request
    raise exc from None
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 196, in handle_async_request
    response = await connection.handle_async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
    return await self._connection.handle_async_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/http11.py", line 143, in handle_async_request
    raise exc
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/http11.py", line 113, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/http11.py", line 186, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_async/http11.py", line 224, in _receive_event
    data = await self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 32, in read
    with map_exceptions(exc_map):
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout

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

Traceback (most recent call last):
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 93, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 148, in simple_response
    await self.app(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/framework/fastapi/fastapi_middleware.py", line 81, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/main.py", line 127, in create_or_update_tenant
    result = await admin.create_or_update_tenant(tenant_id, tenant_config, s)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/admin.py", line 28, in create_or_update_tenant
    result = await multitenancy_api.create_or_update_tenant(tenant_id, config=tenant_config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/recipe/multitenancy/asyncio/__init__.py", line 47, in create_or_update_tenant
    return await recipe.recipe_implementation.create_or_update_tenant(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/recipe/multitenancy/recipe_implementation.py", line 140, in create_or_update_tenant
    response = await self.querier.send_put_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/querier.py", line 394, in send_put_request
    return await self.__send_request_helper(path, "PUT", f, len(self.__hosts))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/querier.py", line 468, in __send_request_helper
    response = await http_function(url, method)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/querier.py", line 392, in f
    return await self.api_request(url, method, 2, headers=headers, json=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/supertokens_python/querier.py", line 115, in api_request
    return await client.put(url, *args, **kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1914, in put
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1559, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1646, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1674, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1711, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_client.py", line 1748, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 370, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/osboxes/Workspace/ui/backend/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 84, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

Timeout is hardcoded here:

Proposal:

rishabhpoddar commented 3 months ago

Hey @ocervell thanks for the issue. We should indeed increase the timeout value. In the meantime, you can call the API to the core directly: https://app.swaggerhub.com/apis/supertokens/CDI/5.1.0#/Multitenancy%20Recipe/createOrUpdateTenantPUT

rishabhpoddar commented 3 months ago

We have increased the timeout to 30s in version 0.24.1