Find the server logs below. It does seem to match what you've quoted.
Do you think the upstream server (uwsgi) is the one not returning the body?
I was able to fix this by consuming the request body in my application before returning the response. However, I'm still wondering how nginx is supposed to behave in such situations.
Log for the request with the larger file:
api-server_1 | [pid: 21|app: 0|req: 1/1] 172.19.0.1 () {38 vars in 601 bytes} [Sat Dec 30 11:14:46 2017] POST / => generated 54 bytes in 2 msecs (HTTP/1.1 403) 2 headers in 78 bytes (1 switches on core 0)
api-server_1 | 2017/12/30 11:14:46 [error] 12#12: *1 readv() failed (104: Connection reset by peer) while reading upstream, client: 172.19.0.1, server: , request: "POST / HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "0.0.0.0:5000"
api-server_1 | 172.19.0.1 - - [30/Dec/2017:11:14:46 +0000] "POST / HTTP/1.1" 403 25 "-" "curl/7.55.1" "-"
With the smaller file:
api-server_1 | 172.19.0.1 - - [30/Dec/2017:11:15:41 +0000] "POST / HTTP/1.1" 403 79 "-" "curl/7.55.1" "-"
api-server_1 | [pid: 20|app: 0|req: 3/4] 172.19.0.1 () {38 vars in 595 bytes} [Sat Dec 30 11:15:41 2017] POST / => generated 54 bytes in 1 msecs (HTTP/1.1 403) 2 headers in 78 bytes (1 switches on core 0)