sanic icon indicating copy to clipboard operation
sanic copied to clipboard

uvicorn (ASGI?) unable to run sanic application

Open paulgessinger opened this issue 1 year ago • 2 comments

Describe the bug Sanic used to work behind uvicorn (ASGI). Now I can't get it to work

Code snippet

# test_app.py
from sanic import Sanic, response


app = Sanic(name="test")


@app.get("/")
async def index(request):
    return response.text("ok")
$ uvicorn test_app:app

uvicorn+sanic then launches with:

INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

but on first request there's a 500 like:

  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/sanic/app.py", line 1297, in __call__
    self._asgi_app = await ASGIApp.create(self, scope, receive, send)
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/sanic/asgi.py", line 167, in create
    await sanic_app.dispatch(
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/sanic/signals.py", line 193, in dispatch
    return await dispatch
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/sanic/signals.py", line 131, in _dispatch
    group, handlers, params = self.get(event, condition=condition)
  File "/home/pagessin/dev/sentinel/.venv/lib/python3.10/site-packages/sanic/signals.py", line 93, in get
    group, param_basket = self.find_route(
TypeError: 'NoneType' object is not callable
INFO:     127.0.0.1:33318 - "GET /status HTTP/1.1" 500 Internal Server Error

Expected behavior Sanic is able to respond to HTTP requests via ASGI.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • sanic==22.6.1
  • uvicorn==0.18.2

Additional context Add any other context about the problem here.

paulgessinger avatar Aug 07 '22 19:08 paulgessinger

Hmm... news to me. Funny that none of the unit tests caught this. But, this is suspect, because we certainly do!

INFO:     ASGI 'lifespan' protocol appears unsupported.

ahopkins avatar Aug 07 '22 19:08 ahopkins

I see the problem. Will release a patch tomorrow.

ahopkins avatar Aug 07 '22 20:08 ahopkins