github
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | issue | performed_via_github_app |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/simonw/datasette/issues/873#issuecomment-650905399 | https://api.github.com/repos/simonw/datasette/issues/873 | 650905399 | MDEyOklzc3VlQ29tbWVudDY1MDkwNTM5OQ== | 9599 | 2020-06-29T05:01:03Z | 2020-06-29T05:01:03Z | OWNER | This is a bit tricky to fix. This change to uvicorn is relevant: https://github.com/encode/uvicorn/commit/a75fe1381f6b1f78901691c71894f3cf487b5d30 | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650906318 | https://api.github.com/repos/simonw/datasette/issues/873 | 650906318 | MDEyOklzc3VlQ29tbWVudDY1MDkwNjMxOA== | 9599 | 2020-06-29T05:04:04Z | 2020-06-29T05:04:12Z | OWNER | Within uvicorn it does this: ```python if port == 0: port = server.sockets[0].getsockname()[1] ``` That `server` variable is later stashed here: ``` self.servers = [server] ``` Where `self` is the instance of `class Server` - which is the class that Uvicorn instantiates and calls `.run()` on when we do `uvicorn.run()` here: https://github.com/simonw/datasette/blob/35aee82c60b2c9a0185b934db5528c8bd11830f2/datasette/cli.py#L409 | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650906533 | https://api.github.com/repos/simonw/datasette/issues/873 | 650906533 | MDEyOklzc3VlQ29tbWVudDY1MDkwNjUzMw== | 9599 | 2020-06-29T05:04:44Z | 2020-06-29T05:04:44Z | OWNER | The challenge is... can we run our own custom code after that line has executed that has access to `server` and can hence access `server.servers[0].sockets[0].getsockname()[1]` to find the port? | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650907323 | https://api.github.com/repos/simonw/datasette/issues/873 | 650907323 | MDEyOklzc3VlQ29tbWVudDY1MDkwNzMyMw== | 9599 | 2020-06-29T05:07:16Z | 2020-06-29T05:07:16Z | OWNER | This line is interesting: is this a hook I can attach to somehow? ```python await self.lifespan.startup() ``` From https://github.com/encode/uvicorn/blob/a75fe1381f6b1f78901691c71894f3cf487b5d30/uvicorn/main.py#L475 | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650908534 | https://api.github.com/repos/simonw/datasette/issues/873 | 650908534 | MDEyOklzc3VlQ29tbWVudDY1MDkwODUzNA== | 9599 | 2020-06-29T05:11:06Z | 2020-06-29T05:11:06Z | OWNER | Uvicorn's lifespan stuff isn't easy to figure out, but this test suite holds some clues: https://github.com/encode/uvicorn/blob/master/tests/test_lifespan.py | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650908854 | https://api.github.com/repos/simonw/datasette/issues/873 | 650908854 | MDEyOklzc3VlQ29tbWVudDY1MDkwODg1NA== | 9599 | 2020-06-29T05:12:04Z | 2020-06-29T05:12:04Z | OWNER | Can I detect the port the server is running on from within the regular Datasette ASGI code? If so I could use that ability and maybe output the magic `--root` link a second after the server starts up somehow. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650909136 | https://api.github.com/repos/simonw/datasette/issues/873 | 650909136 | MDEyOklzc3VlQ29tbWVudDY1MDkwOTEzNg== | 9599 | 2020-06-29T05:12:58Z | 2020-06-29T05:12:58Z | OWNER | On startup Datasette currently outputs: ``` INFO: Waiting for application startup. INFO: ASGI 'lifespan' protocol appears unsupported. INFO: Application startup complete. ``` So the ASGI lifespan protocol is almost certainly the right way to solve this. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650909476 | https://api.github.com/repos/simonw/datasette/issues/873 | 650909476 | MDEyOklzc3VlQ29tbWVudDY1MDkwOTQ3Ng== | 9599 | 2020-06-29T05:14:08Z | 2020-06-29T05:14:08Z | OWNER | I already have a `AsgiLifespan` class: https://github.com/simonw/datasette/blob/35aee82c60b2c9a0185b934db5528c8bd11830f2/datasette/app.py#L896-L905 It runs this function: https://github.com/simonw/datasette/blob/35aee82c60b2c9a0185b934db5528c8bd11830f2/datasette/app.py#L890-L894 Could that startup function also output the `--root` login URL, if needed? | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-650910137 | https://api.github.com/repos/simonw/datasette/issues/873 | 650910137 | MDEyOklzc3VlQ29tbWVudDY1MDkxMDEzNw== | 9599 | 2020-06-29T05:16:32Z | 2020-06-29T05:16:32Z | OWNER | I'm not convinced that function is ever actually being called - I added a `print()` statement to it and it's not executing. I don't think the tests cover it. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-651193131 | https://api.github.com/repos/simonw/datasette/issues/873 | 651193131 | MDEyOklzc3VlQ29tbWVudDY1MTE5MzEzMQ== | 9599 | 2020-06-29T15:27:00Z | 2020-06-29T15:27:00Z | OWNER | Aha! Yes it's not being called, and the reason is this: https://github.com/encode/starlette/issues/486 Short version: by default an exception raised during that phase is silently swallowed! You can avoid the swallowing by adding `lifespan="on"` to the call to `uvicorn.run()`. When I did that here: `uvicorn.run(ds.app(), host=host, port=port, log_level="info", lifespan="on")` The server failed to start with this error: ``` INFO: Started server process [68849] INFO: Waiting for application startup. ERROR: Exception in 'lifespan' protocol Traceback (most recent call last): File ".../uvicorn/lifespan/on.py", line 48, in main await app(scope, self.receive, self.send) File ".../uvicorn/middleware/proxy_headers.py", line 45, in __call__ return await self.app(scope, receive, send) File ".../datasette_debug_asgi.py", line 9, in wrapped_app if scope["path"] == "/-/asgi-scope": KeyError: 'path' ``` | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-651193594 | https://api.github.com/repos/simonw/datasette/issues/873 | 651193594 | MDEyOklzc3VlQ29tbWVudDY1MTE5MzU5NA== | 9599 | 2020-06-29T15:27:46Z | 2020-06-29T15:27:46Z | OWNER | Uninstalling `datasette-debug-asgi` caused the server to startup correctly again. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 | |
https://github.com/simonw/datasette/issues/873#issuecomment-651203178 | https://api.github.com/repos/simonw/datasette/issues/873 | 651203178 | MDEyOklzc3VlQ29tbWVudDY1MTIwMzE3OA== | 9599 | 2020-06-29T15:44:38Z | 2020-06-29T15:44:54Z | OWNER | I'm having real trouble figuring out how to gain access to the port that was used to start the server. I'm treating this as a very low priority - it only affects the exact `-p 0 --root` combination which isn't going to affect many people at all. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
647095487 |