sanic
sanic copied to clipboard
The Sanic built-in server blocks for exactly 90 seconds on status code 412
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
Sanic, like most web servers, usually responds to requests. However, if the response has status code 412, it is very slow and takes exactly 90 extra seconds to respond, stalling after the handler finishes.
This behavior does not happen when running Sanic with uvicorn. Only the official Sanic server. It also doesn't happen with FastAPI.
Code snippet
import sanic
app = sanic.Sanic(__name__)
@app.get("/")
async def root(req: sanic.Request):
status = int(req.args.get("status", "200"))
return sanic.json({"message": "Hello World"}, status=status)
Expected Behavior
sanic main:app --port 8051
Then:
$ curl http://localhost:8051
{"message":"Hello World"}
$ curl http://localhost:8051/?status=400 # fine
{"message":"Hello World"}
$ curl http://localhost:8051/?status=411 # fine
{"message":"Hello World"}
$ curl http://localhost:8051/?status=413 # fine
{"message":"Hello World"}
$ curl http://localhost:8051/?status=412
# stalls with no response for 90 seconds
How do you run Sanic?
Sanic CLI
Operating System
Linux
Sanic Version
Sanic v23.6.0
Additional context
I have reproduced this on both Linux and macOS. I have also reproduced this using both the Sanic CLI and the Sanic.serve()
function programmatically.