Repository: sanic-org/sanic

Issue:
uvicorn (ASGI?) unable to run sanic application
**Describe the bug**
Sanic used to work behind uvicorn (ASGI). Now I can't get it to work


**Code snippet**

```python
# test_app.py
from sanic import Sanic, response


app = Sanic(name="test")


@app.get("/")
async def index(request):
    return response.text("ok")
```

```console
$ 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:

```Traceback (most recent call last):
  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.



Discussion:

Resolving patch:
diff --git a/sanic/app.py b/sanic/app.py
--- a/sanic/app.py
+++ b/sanic/app.py
@@ -1315,7 +1315,7 @@ def update_config(self, config: Union[bytes, str, dict, Any]):
         self.config.update_config(config)
 
     @property
-    def asgi(self):
+    def asgi(self) -> bool:
         return self.state.asgi
 
     @asgi.setter
diff --git a/sanic/mixins/runner.py b/sanic/mixins/runner.py
--- a/sanic/mixins/runner.py
+++ b/sanic/mixins/runner.py
@@ -525,7 +525,7 @@ def motd(
                     )
                 )
             else:
-                server = ""
+                server = "ASGI" if self.asgi else "unknown"  # type: ignore
 
             display = {
                 "mode": " ".join(mode),
@@ -571,8 +571,12 @@ def motd(
 
     @property
     def serve_location(self) -> str:
-        server_settings = self.state.server_info[0].settings
-        return self.get_server_location(server_settings)
+        try:
+            server_settings = self.state.server_info[0].settings
+            return self.get_server_location(server_settings)
+        except IndexError:
+            location = "ASGI" if self.asgi else "unknown"  # type: ignore
+            return f"http://<{location}>"
 
     @staticmethod
     def get_server_location(


Test patch:
diff --git a/tests/test_asgi.py b/tests/test_asgi.py
--- a/tests/test_asgi.py
+++ b/tests/test_asgi.py
@@ -546,3 +546,13 @@ def signal_handler(signal):
     assert response.status_code == 200
     assert response.text == "test_signals_triggered"
     assert signals_triggered == signals_expected
+
+
+@pytest.mark.asyncio
+async def test_asgi_serve_location(app):
+    @app.get("/")
+    def _request(request: Request):
+        return text(request.app.serve_location)
+
+    _, response = await app.asgi_client.get("/")
+    assert response.text == "http://<ASGI>"
diff --git a/tests/test_http.py b/tests/test_http.py
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -76,7 +76,7 @@ def test_full_message(client):
     )
     response = client.recv()
 
-    # AltSvcCheck touchup removes the Alt-Svc header from the 
+    # AltSvcCheck touchup removes the Alt-Svc header from the
     # response in the Python 3.9+ in this case
     assert len(response) == (151 if version_info < (3, 9) else 140)
     assert b"200 OK" in response