Difference between upstream_connect_timeout, upstream_send_timeout and upstream_read_timeout

I’m confused between “upstream_connect_timeout, upstream_send_timeout and upstream_read_timeout”. I’ve gone through documnetation - https://getkong.org/docs/0.10.x/admin-api/#add-api, but still not clear between.


Those values are abstractions of their ngx_http_proxy_module counterparts which exist as NGINX directives: proxy_connect_timeout, proxy_read_timeout, and proxy_send_timeout.

They relate to various timeouts you can set for various steps of the underlying TCP stream between Kong and your remote server(s).

@thibaultcha In order for me to have varying timeouts per API, can I set a bigger timeout inside my custom nginx template (client_body_timeout 1200s; client_header_timeout 1200s;) and then set the upstream timeouts (upstream_send_timeout and upstream_read_timeout) per API to some smaller number per API?

@kkindaface These timeouts are different than the proxy timeouts. But sure, you can edit them.

@thibaultcha The reason i ask is …If i set the nginx level timeouts to some smaller number and my proxy/upstream timeout to a bigger number wont the nginx timeout take precedence and kill the connection even if my upstream timeout is bigger?

No, the Kong ones take precedence (but the timeout properties you referred to are not the same ones, again).

In that case, I am seeing a different behavior. I use 0.11.x. I set my upstream timeouts to 20 mins but looks like the timeout still happens at 60 seconds and I am seeing a 504 Gateway Timeout

what do the nginx level timeouts do?

EDIT: Looks like what I observed is not true, it seems to honor the upstream timeout as soon as I restarted kong. I didn’t think a restart is needed once you edit it from the dashboard

I think I seeing some weird behavior W.R.T the timeouts. The API level timeouts don’t seem to be taking precedence. The timeouts defined inside template file seem to take precedence always.

I have configured the following timeouts in my custom nginx template file (right before the proxy_pass):
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 30m;

And, configured the API level timeouts via the Kong REST API as follows (milliseconds):
upstream_connect_timeout: 3000
upstream_send_timeout: 3000
upstream_read_timeout: 3000

I am seeing a timeout only after 30 minutes and not 3 seconds like one would expect.

What could I be doing wrong?

EDIT 1: The only thing I do different in my custom template is bypass the kong.balancer() phase. It seems to work as expected when I did not use my custom template. Are the timeouts getting set in the balancer phase?

EDIT 2: So it does seem like the overriding timeouts is a feature of the ngx balancer module and so it is getting set in the balancer phase. I was able to get this working for me by adding my own balancer inside the custom nginx template and set the timeout override inside that block since I cant use the kong’s balancer