-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP status 499 seems inappropriate when gateway times out waiting on server #1687
Comments
Hi Brian! I laughed a little at your username. 🤣 Well... A lot of people indicated that HTTP statuses are incorrect/wrong/strange. So, this is Tom's design to override status codes of internal Ocelot's events to remap status to HTTP one. |
QuestionWhich logs in, on what side did you find the 499 error? It seems we have to debug and investigate a behavior in case of OcelotErrorCode.RequestCanceled events. In my own feature branch for #1678 I did some improvements of error codes. But this is docs improvement, not technical change. P.S. In my opinion Ocelot should forward original statuses to upstream clients, but I haven't explored HTTP status logic yet. |
FYI |
@RaynaldM |
Yeah, I found this bug while trying to figure out why we were getting a 499. I submitted a PR to fix it (#1688), not realizing a fix had already been submitted 3 years ago, but just hadn't been merged in. |
The simplest fix would be in the HttpExeptionToErrorMapper class: public class HttpExeptionToErrorMapper : IExceptionToErrorMapper
{
private readonly Dictionary<Type, Func<Exception, Error>> _mappers;
public HttpExeptionToErrorMapper(IServiceProvider serviceProvider)
{
_mappers = serviceProvider.GetService<Dictionary<Type, Func<Exception, Error>>>();
}
public Error Map(Exception exception)
// pass in the HttpContext so the RequestAborted.IsCancellationRequested can be checked
// or just pass in a bool indicating whether the request has been cancelled
{
var type = exception.GetType();
if (_mappers != null && _mappers.ContainsKey(type))
{
return _mappers[type](exception);
}
if (type == typeof(OperationCanceledException) || type.IsSubclassOf(typeof(OperationCanceledException)))
{
// check if IsCancellationRequested to return 499... otherwise return 504
return new RequestCanceledError(exception.Message);
}
if (type == typeof(HttpRequestException))
{
return new ConnectionToDownstreamServiceError(exception);
}
return new UnableToCompleteRequestError(exception);
}
} When I get some time I can try to get a PR together. |
@honestegg |
Expected Behavior / New Feature
When the gateway (Ocelot) times out waiting for the server to respond, I would expect an HTTP error code of 504, not 499. I wouldn't ever expect a 499 to be returned to the client -- that seems like an error that would just end up in the logs indicating that the client cancelled the request.
Actual Behavior / Motivation for New Feature
With the current behavior, a 499 is returned when Ocelot times out waiting for the server to respond.
Specifications
The text was updated successfully, but these errors were encountered: