|
| 1 | + |
| 2 | +**This documentation briefly provides information about the `server side` & `client side` connection timeout settings, in the watch request handler.** |
| 3 | + |
| 4 | +--- |
| 5 | + |
| 6 | +There are two inputs available in the client, that could be used to set connection timeouts: |
| 7 | + |
| 8 | +- `timeout_seconds` |
| 9 | +- `_request_timeout` |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +#### Sever-side timeout (`kwargs['timeout_seconds'] = n`) |
| 14 | + |
| 15 | +- The value of the argument `timeout_seconds`, **n**, (which is time duration in seconds) is consumed at the server side. It is included in the request URL to the server. |
| 16 | + |
| 17 | + *For eg.* ~ `https://localhost:6443/api/v1/namespaces/default/pods?labelSelector=app%3Ddemo&timeoutSeconds=100&watch=True` |
| 18 | + |
| 19 | +- In case, if the `timeout_seconds` value is set, the value `n` would determine the server-side connection timeout duration. |
| 20 | + |
| 21 | + *For eg.* ~ if `kwargs['timeout_seconds'] = 3600`, then the server-side connection timeout will be equal to 1 hour. |
| 22 | + |
| 23 | + This timeout duration is determined by the expression ~ `timeout = time.Duration(3600) * time.seconds`, *i.e.* `timeout = 1 hour` |
| 24 | + |
| 25 | + ***Refer:*** |
| 26 | + - *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L254)* |
| 27 | + |
| 28 | +- In case, if the `timeout_seconds` value is not set, then the connection timeout will be a randomized value (in seconds) between `minRequestTimeout` and 2*`minRequestTimeout`, to spread out the load. |
| 29 | + |
| 30 | + It is determined using the expression ~ `timeout = time.Duration(float64(minRequestTimeout) * (rand.Float64() + 1.0))` |
| 31 | + |
| 32 | + Where `minRequestTimeout` indicates the minimum number of seconds a handler must keep a request open before timing it out. |
| 33 | + |
| 34 | + The default value of `minRequestTimeout` is 1800 seconds. |
| 35 | + |
| 36 | + ***Refer:*** |
| 37 | + - *[https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257](https://github.com/kubernetes/apiserver/blob/release-1.20/pkg/endpoints/handlers/get.go#L257)* |
| 38 | + - *[https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320](https://github.com/kubernetes/kubernetes/blob/release-1.20/staging/src/k8s.io/apiserver/pkg/server/config.go#L320)* |
| 39 | + |
| 40 | +- In case of a network outage, this timeout value will have no effect & the client will hang indefinitely without raising any exception. |
| 41 | + |
| 42 | +- It is recommended to set this timeout value to a higher number such as 3600 seconds (1 hour). |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +#### Client-side timeout (`kwargs['_request_timeout'] = n`) |
| 47 | + |
| 48 | +- The value of the argument `_request_timeout`, **n** (which is time duration in seconds) is set to the socket used for the connection. |
| 49 | + |
| 50 | +- In case, if the `_request_timeout` value is set, this argument can accept 2 types of input values ~ |
| 51 | + - float, |
| 52 | + - a tuple (with a length of 2) |
| 53 | + |
| 54 | + ***Refer*** |
| 55 | + - *[https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339](https://github.com/kubernetes-client/python/blob/v17.17.0/kubernetes/client/api_client.py#L336-L339)* |
| 56 | + |
| 57 | + If it is tuple input type i.e. a pair of values like (connection, read), then the first value will be ignored. |
| 58 | + |
| 59 | +- In case of network outage, leading to dropping all packets with no RST/FIN, the timeout value (in seconds) determined by the `request_timeout` argument, would be the time duration for how long the client will wait before realizing & dropping the connection. |
| 60 | + |
| 61 | +- When the timeout happens, an exception will be raised, for eg. ~ |
| 62 | + |
| 63 | + `urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='localhost', port=6443): Read timed out.` |
| 64 | + |
| 65 | +- In case, if the `_request_timeout` value is not set, then the default value is **`None`** & socket will have no timeout. |
| 66 | + |
| 67 | + ***Refer:*** |
| 68 | + - *[https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout](https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout)* |
| 69 | + |
| 70 | +- It is recommended to set this timeout value to a lower number (for eg. ~ maybe 60 seconds). |
| 71 | + |
0 commit comments