Describe the bug
I've found that a simple endpoint with status_code=204 is causing gunicorn to shutdown when running on Google appengine.
I suspect the bug is probably outside of FastAPI (eg maybe in uvicorn?), but I haven't yet managed to reproduce it with a simpler stack, and maybe this will help others with the same issue.
To Reproduce
- Create the following:
main.py:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.delete("/", status_code=204)
def delete_root():
print("deleted a thing...")
return ""
requirements.txt:
app.yaml:
runtime: python37
instance_class: F1
entrypoint: gunicorn --bind :$PORT --workers 1 --worker-class uvicorn.workers.UvicornWorker main:app
handlers:
- url: /.*
secure: always
script: auto
- Install gcloud cli, login to gcloud and then deploy to appengine with:
- Call the delete endpoint
curl -XDELETE https://YOURPROJECT.appspot.com
- It hangs for a couple of seconds and then returns an error like this:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>500 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The server encountered an error and could not complete your request.<p>Please try again in 30 seconds.</h2>
<h2></h2>
</body></html>
And logs as follows:
2020-05-23 15:08:11.658 NZST deleted a thing...
2020-05-23 15:08:13.193 NZST [start] 2020/05/23 03:08:13.192900 Quitting on terminated signal
2020-05-23 15:08:13.198 NZST [2020-05-23 03:08:13 +0000] [7] [INFO] Handling signal: term
2020-05-23 15:08:13.259 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Shutting down
2020-05-23 15:08:13.259 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Error while closing socket [Errno 9] Bad file descriptor
2020-05-23 15:08:13.360 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Waiting for application shutdown.
2020-05-23 15:08:13.360 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Application shutdown complete.
2020-05-23 15:08:13.360 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Finished server process
2020-05-23 15:08:13.361 NZST [2020-05-23 03:08:13 +0000] [15] [INFO] Worker exiting (pid: 15)
2020-05-23 15:08:13.502 NZST [2020-05-23 03:08:13 +0000] [7] [INFO] Shutting down: Master
2020-05-23 15:08:13.556 NZST [start] 2020/05/23 03:08:13.555603 Start program failed: termination triggered by nginx exit
- But I expected it to return an empty body with http status 204.
Note - changing status code to something else, eg 200 resolves the issue.
Expected behavior
I expected an empty 204 response to be returned.
Environment
-
OS: Linux (appengine)
-
FastAPI Version
0.54.2
3.7 (whatever as used by appengine)
See also
Cross-post on the appengine issue tracker https://issuetracker.google.com/issues/157312477
Describe the bug
I've found that a simple endpoint with status_code=204 is causing gunicorn to shutdown when running on Google appengine.
I suspect the bug is probably outside of FastAPI (eg maybe in uvicorn?), but I haven't yet managed to reproduce it with a simpler stack, and maybe this will help others with the same issue.
To Reproduce
main.py:
requirements.txt:
app.yaml:
And logs as follows:
Note - changing status code to something else, eg 200 resolves the issue.
Expected behavior
I expected an empty 204 response to be returned.
Environment
OS: Linux (appengine)
FastAPI Version
0.54.2
3.7 (whatever as used by appengine)
See also
Cross-post on the appengine issue tracker https://issuetracker.google.com/issues/157312477