Run ASGI lifespan startup *after* port binding occurs
@@ -329,11 +329,6 @@ class Server:
async def startup(self, sockets=None):
config = self.config
- await self.lifespan.startup()
- if self.lifespan.should_exit:
- self.should_exit = True
- return
-
create_protocol = functools.partial(
config.http_protocol_class, config=config, server_state=self.server_state
)
@@ -381,6 +376,10 @@ class Server:
self.logger.info(message % (protocol_name, config.host, config.port))
self.servers = [server]
+ await self.lifespan.startup()
+ if self.lifespan.should_exit:
+ self.should_exit = True
+ else:
self.started = True
async def main_loop(self):
