{"action":"created","issue":{"url":"https://api.github.com/repos/python-trio/snekomatic/issues/6","repository_url":"https://api.github.com/repos/python-trio/snekomatic","labels_url":"https://api.github.com/repos/python-trio/snekomatic/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/python-trio/snekomatic/issues/6/comments","events_url":"https://api.github.com/repos/python-trio/snekomatic/issues/6/events","html_url":"https://github.com/python-trio/snekomatic/issues/6","id":483096021,"node_id":"MDU6SXNzdWU0ODMwOTYwMjE=","number":6,"title":"Graceful shutdown / SIGTERM","user":{"login":"njsmith","id":609896,"node_id":"MDQ6VXNlcjYwOTg5Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/609896?v=4","gravatar_id":"","url":"https://api.github.com/users/njsmith","html_url":"https://github.com/njsmith","followers_url":"https://api.github.com/users/njsmith/followers","following_url":"https://api.github.com/users/njsmith/following{/other_user}","gists_url":"https://api.github.com/users/njsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/njsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/njsmith/subscriptions","organizations_url":"https://api.github.com/users/njsmith/orgs","repos_url":"https://api.github.com/users/njsmith/repos","events_url":"https://api.github.com/users/njsmith/events{/privacy}","received_events_url":"https://api.github.com/users/njsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-08-20T21:38:54Z","updated_at":"2019-08-21T09:08:10Z","closed_at":null,"author_association":"MEMBER","body":"When Heroku decides to restart our app (e.g. for an upgrade, or just automatically once a day), it [sends SIGTERM and then waits 30 seconds for it to exit](https://devcenter.heroku.com/articles/dynos#graceful-shutdown-with-sigterm).\r\n\r\nRight now, we don't have any SIGTERM handling at all, so \r\n\r\nThis creates some race conditions: for example, suppose that a PR is merged into this repo by a new contributor. This kicks off two processes:\r\n\r\n- snekomatic sees that it's a new contributor's first PR, and tries to invite them and post a comment\r\n- heroku sees that there's a new commit in snekomatic, and tries to reboot snekomatic to pick up the changes\r\n\r\nIn practice we kinda get away with it, because it takes heroku a few seconds to notice the new commit and then build a new container image, so snekomatic wins the race. But if snekomatic gets fancier and starts doing more, this will become more of a problem.\r\n\r\nIt's easy to have a task listen for SIGTERM. But after it gets it, what should it do? I guess we want to do a graceful shutdown of hypercorn (i.e. finish processing current requests, but stop accepting new ones). I don't think hypercorn has any support for this? And Trio doesn't make it particularly easy yet either (cf https://github.com/python-trio/trio/issues/147).\r\n\r\nOh, no, I'm wrong: hypercorn has a config option `shutdown_event` that it uses for doing graceful shutdown when running in multi-process mode. Maybe we can use this when from API mode too? Is it just as simple as passing `shutdown_event=some_trio_event_object` as part of our config? CC @pgjones"},"comment":{"url":"https://api.github.com/repos/python-trio/snekomatic/issues/comments/523369286","html_url":"https://github.com/python-trio/snekomatic/issues/6#issuecomment-523369286","issue_url":"https://api.github.com/repos/python-trio/snekomatic/issues/6","id":523369286,"node_id":"MDEyOklzc3VlQ29tbWVudDUyMzM2OTI4Ng==","user":{"login":"njsmith","id":609896,"node_id":"MDQ6VXNlcjYwOTg5Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/609896?v=4","gravatar_id":"","url":"https://api.github.com/users/njsmith","html_url":"https://github.com/njsmith","followers_url":"https://api.github.com/users/njsmith/followers","following_url":"https://api.github.com/users/njsmith/following{/other_user}","gists_url":"https://api.github.com/users/njsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/njsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/njsmith/subscriptions","organizations_url":"https://api.github.com/users/njsmith/orgs","repos_url":"https://api.github.com/users/njsmith/repos","events_url":"https://api.github.com/users/njsmith/events{/privacy}","received_events_url":"https://api.github.com/users/njsmith/received_events","type":"User","site_admin":false},"created_at":"2019-08-21T09:08:10Z","updated_at":"2019-08-21T09:08:10Z","author_association":"MEMBER","body":"@pgjones I'm using `hypercorn.trio.serve`"}}
{"actor":{"display_login":"njsmith"}}