Recently we had issue with one of our endpoints which usually takes a lot time to return response. This is expected behaviour for that endpoint but the issue was that in CCv2 we started receiving 502 Bad Gateway errors as a response.
As we know HTTP 502 bad gateway indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server. It occurs when:
- The timeout of the proxy was reached prior to the request completion.
- If the connection proxy > server drops.
- The response from the server is invalid.
In our case the problem was related with the Proxy timeout:
There are 2 general options to resolve this kind of a issue:
- Optimize the code so the endpoint takes less time.
- Increase the Proxy timeout.
Unfortunately first option was not valid for us that’s why we applied the second one(increased the timeout to 2 mins).
In CCv2 the default Proxy timeout is 1 minute. But we can increase it from CCv2 Endpoint settings:
Enviroment -> Endpoint(API in our case) -> Proxy Timeout and save it.
Impotrant: the changes will be applied automatically without need of service restart.
This way we can make sure that if for some reason the response takes longer time, there won’t be a 502 Bad Gateway error.
As the proxy timeout is an important security feature, avoid entering too high a value in this field.