Raise when "after_server_start", then sanic Fake Death

Phenomenon

After sanic server start, I need to get some basic/update information from some other server. I use aiohttp to make a post to some server, but sometimes it raises because of some net problem. Them sanic server came into a state like Fake Death. It is in Up state checking from my supervisor. But no request could be sent to the sanic server. And supervisor cannot restart it because it’s Up.

Solution

  1. I tried exit(), quit(), sys.exit() when Exception during “after server start”. Nothing works, in supervisor the sanic server is still Up.
  2. I tried to use os.kill(), then it works!

Problem

Why sanic server won’t reload itself when raise in “after_server_start”?

Can you provide some simplified sample code that reproduces this? What kind of exception is being raised?

It’s a normal case. Here is the code:

@app.listener("after_server_start")
async def after_start(app, loop):
    raise   # whatever raise a exception

Just after this, the server came into Fake Death state.

Thanks, I’ll take a look and get back to you later this weekend as soon as I have a chance.

@DavidDing14 Looking at this, I am assuming what you mean is that when you have auto-reload enabled and there is an exception in the listeners, then the reload instance does not exit. Yes? Because if you do not have auto-reload on, then the application exits.

I do think that this is desired behavior though, as it allows a developer the opportunity to work to fix the exception without needing to constantly restart the application.

If you are observing something else, please LMK by including the Sanic version number you are working on.

1 Like

Thanks a lot! :heart: :heart: :heart:
I just want to share something I’ve never found anywhere else. If anyone else came across anything similar, this may be a help.

1 Like