Connection reset by peer on file upload if JWT expires

28 views
Skip to first unread message

Larry Martell

unread,
Jun 2, 2023, 4:54:16 PM6/2/23
to django...@googlegroups.com
We have a django app and it supports a file upload request. The entire
upload comprises multiple requests. We are authenticating with JWT and
we have logic to handle a 401 and in that case use the refresh token
to get a new access token and resend the failed request. However if
the token expires between 2 requests of the same upload the 401
response never makes it to the client. In the logs I found that before
nginx gets the response we get this error:

2023/06/02 16:23:11 [error] 1924925#1924925: *75 readv() failed (104:
Connection reset by peer) while reading upstream, client: xx.xx.xx.xx,
server: foo.com, request: "POST /api/upload/ HTTP/1.1", upstream:
"uwsgi://unix:///bar/foo/our_app/app.sock:", host: "foo.com",
referrer: "http://foo.com:8082/"

This causes the client to get an empty response body and the browser
throws a ERR_CONTENT_LENGTH_MISMATCH error. The entire upload takes
under 10 minutes and we have all the timeouts set to 100 minutes:

uwsgi_read_timeout 6000;
uwsgi_connect_timeout 6000;
uwsgi_send_timeout 6000;
send_timeout 6000;
proxy_read_timeout 6000;
proxy_send_timeout 6000;

What is causing the socket to get closed? How can I prevent that? Are
there other timeouts I could set? Any logging that I can enable to see
why the socket is getting closed? Is there a way to detect this in
code so it can be retried?
Reply all
Reply to author
Forward
0 new messages