reverse-proxy icon indicating copy to clipboard operation
reverse-proxy copied to clipboard

Why does Yarp return 502 status code when a client disconnects?

Open adriaanp opened this issue 2 years ago • 4 comments
trafficstars

502 (Bad Gateway) is usually returned when the reverse proxy encounters an error while trying to forward the request to the backend server, but in the case where a client disconnects should it not set the status code to 499?

adriaanp avatar Feb 02 '23 04:02 adriaanp

By "return", are you just referring to the values you see in logs? By definition, the client won't see the value.

MihaZupan avatar Feb 02 '23 14:02 MihaZupan

Yes, that's correct, the client won't see the value, I meant in logs and observability tools like new relic.

adriaanp avatar Feb 02 '23 19:02 adriaanp

499 is a non-standard code that NGinx made up. It being a defacto standard might be sufficient cause to use it though.

In general, you should look at the ForwarderError for a more detailed explanation. https://github.com/microsoft/reverse-proxy/blob/79a7b806688311fd2cca2ca67dc7cc418c7925ab/src/ReverseProxy/Forwarder/ForwarderError.cs#L39

Tratcher avatar Feb 02 '23 20:02 Tratcher

We're starting to use 499 in AspNetCore for this situation as well: https://github.com/dotnet/aspnetcore/pull/46330

If that goes through then we should do something similar here. We'll even be able to use the new constant on .NET 8.

Tratcher avatar Feb 07 '23 18:02 Tratcher