Nginx converts 409 from upstream to 502

classic Classic list List threaded Threaded
2 messages Options
xrd
Reply | Threaded
Open this post in threaded view
|

Nginx converts 409 from upstream to 502

xrd
Hi,

Our request flow looks like this:

client --> nginx --> haproxy --> tomcat

Put requests with large bodies are used to upload files. Sometimes due to
some application logic, tomcat may reject an upload early and return 409,
tomcat does not drain the input stream, we do not want to read the input
stream and rather reject early.

When tomcat rejects a PUT request early with 409, tomcat access logs show
409. The haproxy fronting tomcats also log a 409 in access logs, but nginx
logs a 502 and sends a 502 to the clients. It looks like nginx does not like
that request is rejected and a 409 is sent without reading the full request
by the upstream.

What can we do to make sure client receives the correct response code i.e.
409

Thanks
Sachin

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286531,286531#msg-286531

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx converts 409 from upstream to 502

Maxim Dounin
Hello!

On Sat, Dec 21, 2019 at 07:49:06AM -0500, [hidden email] wrote:

> Our request flow looks like this:
>
> client --> nginx --> haproxy --> tomcat
>
> Put requests with large bodies are used to upload files. Sometimes due to
> some application logic, tomcat may reject an upload early and return 409,
> tomcat does not drain the input stream, we do not want to read the input
> stream and rather reject early.
>
> When tomcat rejects a PUT request early with 409, tomcat access logs show
> 409. The haproxy fronting tomcats also log a 409 in access logs, but nginx
> logs a 502 and sends a 502 to the clients. It looks like nginx does not like
> that request is rejected and a 409 is sent without reading the full request
> by the upstream.
>
> What can we do to make sure client receives the correct response code i.e.
> 409

The 502 error suggests that nginx do not receive HTTP response
from the upstream server.  Most likely reason is that haproxy
closes connection with nginx without trying to read data which is
in socket buffers and/or in transit, resulting in connection
reset.  See
http://mailman.nginx.org/pipermail/nginx/2019-December/058812.html 
for details.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx