{"html_url": "https://github.com/simonw/datasette/issues/1955#issuecomment-1357084279", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1955", "id": 1357084279, "node_id": "IC_kwDOBm6k_c5Q43Z3", "user": {"value": 178162, "label": "andrewdotn"}, "created_at": "2022-12-19T04:34:16Z", "updated_at": "2022-12-19T04:34:16Z", "author_association": "NONE", "body": "You were super-close on the python version of the test here, changing `http` to `https` on 8b73fc6b47dffd8836f5c58aae1e57c1f66a5754 is enough to pass the test:\r\n\r\n```diff\r\ndiff --git a/tests/conftest.py b/tests/conftest.py\r\nindex 69dee68b4a3f..ba07a11d37f6 100644\r\n--- a/tests/conftest.py\r\n+++ b/tests/conftest.py\r\n@@ -207,7 +207,7 @@ def ds_localhost_https_server(tmp_path_factory):\r\n stderr=subprocess.STDOUT,\r\n cwd=tempfile.gettempdir(),\r\n )\r\n- wait_until_responds(\"http://localhost:8042/\", verify=client_cert)\r\n+ wait_until_responds(\"https://localhost:8042/\", verify=client_cert)\r\n # Check it started successfully\r\n assert not ds_proc.poll(), ds_proc.stdout.read().decode(\"utf-8\")\r\n yield ds_proc, client_cert\r\n```\r\n\r\nMy speculation about what was happening here: when `wait_until_responds()` would time out due to SSL connection problems, because `.terminate()` isn\u2019t in a `finally`, the datasette process wouldn\u2019t get killed. That could (1) hang CI and (2) cause all your future local test runs to mysteriously fail because they\u2019d be secretly talking to that old datasette process still hanging around from a past test run with an old temporary server certificate, and that old server cert wouldn\u2019t validate against your newly-created ca cert.\r\n\r\nA `finally` for `.terminate()` would help; a fancier version could be a context manager for running the external `datasette` process that could:\r\n - ensure the process always exited when no longer needed\r\n - if you want to be fancy, call `terminate()`, `wait()` for a short timeout for the process to exit, then try `kill()` and `wait()` again; raise an exception complaining about the seemingly-unkillable process if all that fails\r\n - raise an error if the process exited with a non-zero error code; here it\u2019s likely that some `datasette` executions were secretly failing with `[Errno 48] error while attempting to bind on address ('127.0.0.1', 8042): address already in use`", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1496652622, "label": "invoke_startup() is not run in some conditions, e.g. gunicorn/uvicorn workers, breaking lots of things"}, "performed_via_github_app": null}