question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

restart workers online (graceful restart) to hot reload, in production environment.

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

Condition: keep service available any time.

---- client code----

async def run():                                                                                        
    while 1:
        await post('http://127.0.0.1:8000/') 

when called app.m.restart(“ALL_PROCESSES”) in a worker, sanic crashed.

---- server code ----

@app.post("/")
async def handler(request):
    app.m.restart('__ALL_PROCESSES__')
    return response.text('ok')


if __name__ == "__main__":
    app.run(debug=True, workers=2)

Describe the solution you’d like

graceful restarting and reduce the effect when restarting. my messy describe:

  1. graceful restart workers; restart all workers will not crash, if only 1 worker, block a little while (if worker not started yet) is ok.
  2. a way to graceful restart worker one by one, code eg: woker_names = tuple(app.m.workers.keys()) for woker_name in worker_names: ret_val = app.m.restart(worker_name) # here, the worker has been graceful restarted, ret_val is meaningful
  3. may combine the above 2, when restarting all workers, 50% workers restarting, 50% old workers keep serving

Additional context

simplify the api,

app.m.restart('__ALL_PROCESSES__')   => app.m.restart_all()

thanks.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
yangbo1024commented, Dec 9, 2022

I think it’s okay to do a good job of HTTP link processing with short responses, and the same is true for my personal needs. Restarting the main process, modifying the IP address and port is not considered. For some long-term services, such as websockets, streams, etc., they can be handled by sanic user, including but not limited to deliberately increasing the waiting time for graceful closing. Otherwise, the sanic becomes too complex and even brings more bugs, which is not friendly to the majority of users.

1reaction
yangbo1024commented, Dec 8, 2022

amazing! thats it

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Art of Graceful Reloading — uWSGI 2.0 documentation
Requires --lazy-apps option. To trigger it: ... It will wait for running workers and then restart each of them. Pros: ... Cons: no...
Read more >
Gracefully Restart Nginx Web Server After Config Update
QUIT : Graceful shutdown; KILL : Halts a stubborn process; HUP : Configuration reload. Start the new worker processes with a new configuration....
Read more >
Settings — Gunicorn 20.1.0 documentation
reload. Restart workers when code changes. This setting is intended for development. It will cause workers to be restarted whenever application code changes....
Read more >
How to correctly reset, restart, and recycle IIS websites
Start sending NEW requests to the new worker process. Tell the current worker process process to shut down, finishing out any existing requests...
Read more >
puma/restart.md at master - GitHub
Phased restarts replace all running workers in a Puma cluster. This is a useful way to upgrade the application that Puma is serving...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found