Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

granian 1.7.0 breaks compatiblity with starlette/fastapi if middlewares applied #467

Closed
jvllmr opened this issue Dec 16, 2024 · 2 comments · Fixed by #468
Closed

granian 1.7.0 breaks compatiblity with starlette/fastapi if middlewares applied #467

jvllmr opened this issue Dec 16, 2024 · 2 comments · Fixed by #468

Comments

@jvllmr
Copy link

jvllmr commented Dec 16, 2024

After upgrading to granian 1.7.0 I receive the following upon the first request:

jan@NB1700 ~/d/tooltime (0.5.x)> granian --interface asgi tooltime.wsgi:app
[INFO] Starting granian (main PID: 8519)
[INFO] Listening at: http://127.0.0.1:8000
[INFO] Spawning worker-1 with pid: 8520
[INFO] Started worker-1
[INFO] Started worker-1 runtime-1
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/granian/_futures.py", line 11, in future_watcher
    await inner(watcher.scope, watcher.proto)
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 186, in __call__
    async with anyio.create_task_group() as task_group:
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in __aenter__
    self.cancel_scope.__enter__()
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 425, in __enter__
    task_state = _task_states[host_task]
                 ~~~~~~~~~~~~^^^^^^^^^^^
  File "/home/jan/dev/tooltime/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 686, in __getitem__
    assert isinstance(key, asyncio.Task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 

The error does not occur when downgrading granian to 1.6.4 or removing all my middlewares.

I have the following middlewares:

app.add_middleware(BaseHTTPMiddleware, dispatch=exception_middleware)
app.add_middleware(BaseHTTPMiddleware, dispatch=file_middleware)
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=current_config.trusted_hosts)

where ProxyHeadersMiddleware comes from uvicorn.

@jvllmr jvllmr changed the title granian 1.7.0 breaks compatiblity with starlette/fastapi if middlewares granian 1.7.0 breaks compatiblity with starlette/fastapi if middlewares applied Dec 16, 2024
@gi0baro
Copy link
Member

gi0baro commented Dec 16, 2024

@jvllmr can you try with #468 ?

@jvllmr
Copy link
Author

jvllmr commented Dec 16, 2024

I have tested the PR in the same codebase and the issue seems to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants