Nginx + uWSGI + Django return 502 on large request and expired session

I have a Django view that processes a POST request with a random size (between 20 char to 30k char). This API is available only to registered users and is checked by the session header. The API works well with my test scripts, but I noticed about 502 Nginx logs. The error log shows this line:

2016/12/26 19:53:15 [error] 1048#0: *72 sendfile() failed (32: Broken pipe) while sending request to upstream, client: XXX.XXX.XXX.XXX, server: , request: "POST /api/v1/purchase HTTP/1.1", upstream: "uwsgi://unix:///opt/project/sockets/uwsgi.sock:", host: "staging.example.com"

After some tests, I was able to recover this call with a large body request.

curl -XPOST https://staging.example.com/api/v1/purchase \
-H "Accept: application/json" \
-H "token: development-token" \
-H "session: bad-session" \
-i -d '{"receipt-data": "<25677 character string>"}'
HTTP/1.1 100 Continue

HTTP/1.1 502 Bad Gateway
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 26 Dec 2016 19:54:32 GMT
Content-Type: text/html
Content-Length: 181
Connection: keep-alive

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>

It seems that Django checks that the session is invalid and returns a response (403) before the client completes the body delivery.

If I am right, is there any way to get Django to send this status 100 after checking the headers instead of Nginx?

, , ?

+4

Source: https://habr.com/ru/post/1664943/


All Articles