tomchristie: Looks great! Let’s make sure we’ve also got a new release of Starlette that handles *both* cases before we merge this in and release.
diff --git a/uvicorn/lifespan.py b/uvicorn/lifespan.py
index aa53860..e419beb 100644
--- a/uvicorn/lifespan.py
+++ b/uvicorn/lifespan.py
@@ -7,12 +7,12 @@ STATE_TRANSITION_ERROR = 'Got invalid state transition on lifespan protocol.'
 
 
 class Lifespan:
-    def __init__(self, app, logger=None, startup_timeout=10, cleanup_timeout=10):
+    def __init__(self, app, logger=None, startup_timeout=10, shutdown_timeout=10):
         self.logger = logger or logging.getLogger("uvicorn")
         self.startup_timeout = startup_timeout
-        self.cleanup_timeout = cleanup_timeout
+        self.shutdown_timeout = shutdown_timeout
         self.startup_event = asyncio.Event()
-        self.cleanup_event = asyncio.Event()
+        self.shutdown_event = asyncio.Event()
         self.receive_queue = asyncio.Queue()
         try:
             self.asgi = app({'type': 'lifespan'})
@@ -39,12 +39,12 @@ class Lifespan:
     async def send(self, message):
         if message['type'] == 'lifespan.startup.complete':
             assert not self.startup_event.is_set(), STATE_TRANSITION_ERROR
-            assert not self.cleanup_event.is_set(), STATE_TRANSITION_ERROR
+            assert not self.shutdown_event.is_set(), STATE_TRANSITION_ERROR
             self.startup_event.set()
-        elif message['type'] == 'lifespan.cleanup.complete':
+        elif message['type'] == 'lifespan.shutdown.complete':
             assert self.startup_event.is_set(), STATE_TRANSITION_ERROR
-            assert not self.cleanup_event.is_set(), STATE_TRANSITION_ERROR
-            self.cleanup_event.set()
+            assert not self.shutdown_event.is_set(), STATE_TRANSITION_ERROR
+            self.shutdown_event.set()
         else:
             error = 'Got invalid message type on lifespan protocol "%s"'
             raise RuntimeError(error % message['type'])
@@ -57,6 +57,6 @@ class Lifespan:
         await self.receive_queue.put({'type': 'lifespan.startup'})
         await asyncio.wait_for(self.startup_event.wait(), timeout=self.startup_timeout)
 
-    async def wait_cleanup(self):
-        await self.receive_queue.put({'type': 'lifespan.cleanup'})
-        await asyncio.wait_for(self.cleanup_event.wait(), timeout=self.cleanup_timeout)
+    async def wait_shutdown(self):
+        await self.receive_queue.put({'type': 'lifespan.shutdown'})
+        await asyncio.wait_for(self.shutdown_event.wait(), timeout=self.shutdown_timeout)
diff --git a/uvicorn/main.py b/uvicorn/main.py
index 5119352..2066a0c 100644
--- a/uvicorn/main.py
+++ b/uvicorn/main.py
@@ -410,7 +410,7 @@ class Server:
 
         if self.lifespan.is_enabled:
             self.logger.info("Waiting for application cleanup.")
-            await self.lifespan.wait_cleanup()
+            await self.lifespan.wait_shutdown()
 
         self.loop.stop()
 
diff --git a/uvicorn/middleware/wsgi.py b/uvicorn/middleware/wsgi.py
index 82e45ec..901a260 100644
--- a/uvicorn/middleware/wsgi.py
+++ b/uvicorn/middleware/wsgi.py
@@ -55,6 +55,7 @@ class WSGIMiddleware:
         self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=workers)
 
     def __call__(self, scope):
+        assert scope["type"] == "http"
         return WSGIResponder(self.app, self.executor, scope)
 
 

Lifespan `cleanup` should become `shutdown`
Naming in ASGI spec recently tweaked here. Good one of a contributor to jump on.
We’re first want to update Starlette to deal with *either* of the two names.
diff --git a/tests/test_lifespan.py b/tests/test_lifespan.py
index 8efb414..642d71e 100644
--- a/tests/test_lifespan.py
+++ b/tests/test_lifespan.py
@@ -14,7 +14,7 @@ class LifespanContext:
         return self.app
 
     async def __aexit__(self, exc_type, exc, tb):
-        await self.lifespan.wait_cleanup()
+        await self.lifespan.wait_shutdown()
 
 
 def test_lifespan_enabled():
@@ -40,9 +40,9 @@ def test_lifespan():
             startup_complete = True
             await send({'type': 'lifespan.startup.complete'})
             message = await receive()
-            assert message['type'] == 'lifespan.cleanup'
+            assert message['type'] == 'lifespan.shutdown'
             cleanup_complete = True
-            await send({'type': 'lifespan.cleanup.complete'})
+            await send({'type': 'lifespan.shutdown.complete'})
         return lifespan
 
     async def test(app):

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov requests codecov
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
click==8.1.8
codecov==2.1.13
coverage==7.2.7
exceptiongroup==1.2.2
h11==0.14.0
httptools==0.6.0
idna==3.10
importlib-metadata==6.7.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
pytest-cov==4.1.0
requests==2.31.0
tomli==2.0.1
typing_extensions==4.7.1
urllib3==2.0.7
-e git+https://github.com/encode/uvicorn.git@c754a22105e4f9399222ec16ac7c5fdaf832784c#egg=uvicorn
uvloop==0.18.0
websockets==11.0.3
wsproto==1.2.0
zipp==3.15.0

name: uvicorn
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - charset-normalizer==3.4.1
      - click==8.1.8
      - codecov==2.1.13
      - coverage==7.2.7
      - exceptiongroup==1.2.2
      - h11==0.14.0
      - httptools==0.6.0
      - idna==3.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - packaging==24.0
      - pluggy==1.2.0
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - requests==2.31.0
      - tomli==2.0.1
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - uvloop==0.18.0
      - websockets==11.0.3
      - wsproto==1.2.0
      - zipp==3.15.0
prefix: /opt/conda/envs/uvicorn

tests/test_lifespan.py::test_lifespan
tests/test_lifespan.py::test_lifespan_enabled
uvicorn/middleware/wsgi.py uvicorn/lifespan.py uvicorn/main.py
uvicorn/middleware/wsgi.py uvicorn/lifespan.py uvicorn/main.py