AssertionError: App must be running before you can run middleware!

I’ve started seeing this error: AssertionError('App must be running before you can run middleware!')

This happens within seconds after the server is re-deployed, and happens for a few seconds only. It’s not a big issue as it goes away after the app is running, but I would’ve preferred if it does what it’s always done before, which is to simply return a 503 before the server has completely started.

What is causing this?

My sanic version:


What plug-ins are you using? It comes from plugin framework

Also, that’s a pretty old version that is no longer supported. You should at least try to upgrade to the LTS.

I was previously told to not upgrade to the latest version here: Language-specific URLs for SEO?

So I’ve never upgraded and was waiting to hear when I should be upgrading. Should I upgrade?

But yes, if the plugin framework was causing issue then it would make sense, as I did add the CORS plugin a couple of months ago and it uses that plugin.

Ok I have now upgraded sanic and also SPF, but now I am getting this:

RuntimeError: SPF processing a request before App server is started.

I am not entirely sure where I should fix this. Am I supposed to, for example, initialize the plugin elsewhere? right now I just put it in the but am I supposed to perhaps put it inside the before_server_start block?

Are you running Sanic server or an ASGI server? I ran into that here:

I am running on gunicorn. However, I see that error message whether in production using gunicorn or in local dev (which simply runs two workers by calling the sanic module directly) — if I try to call some end points before the app is fully started.

I didn’t actually look into ASGI. This is a new option? I guess I should check that out!