kubernetes: kube-apiserver: some HTTP requests might hang indefinitely
What happened?
Since kube-apiserver doesn’t specify a WriteTimeout on the server level it solely relies on the timeout filter to terminate HTTP requests.
The timeout filter wraps the http.ResponseWriter into a time-aware construct and passes it to an HTTP handler. Once the specified timeout has elapsed the HTTP handler loses control and an appropriate response is sent back to a client.
The issue arises when a response written via the http.ResponseWriter.Write method cannot be sent to the client. In that scenario, the timeout handler won’t be able to terminate the connection because it cannot acquire a lock and the HTTP request will hang forever.
The Write method does not always send immediately data to the client. Most of the time anything sent via the Write method is actually stored in a memory buffer and sent to the client at a later time. It only sends data immediately when the buffer is sufficiently large.
Now, with the introduction of HTTP2/ping feature, stale connections are detected and terminated. But what if the connection isn’t stale but the client is still slow to download data? Exactly in those cases, the kube-apiserver won’t be able to terminate hanging HTTP requests.
What did you expect to happen?
the kube-apiserver should always terminate timed-out HTTP requests.
How can we reproduce it (as minimally and precisely as possible)?
- update the
OpenAPIspec so that it exceeds the HTTP buffer. - send an HTTP request for that spec but don’t actually download it. (not closing the
ResponseBodydoes the trick). For example:
req, _ := http.NewRequest("GET", `/openapi/v2`, nil)
resp, _ := rt.RoundTrip(req)
// don't close the rsp body, usually you would: resp.Body.Close()
// sleep for 1 hour
Anything else we need to know?
No response
Kubernetes version
$ kubectl version
# paste output here
n/a
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 19 (16 by maintainers)
/remove-lifecycle stale /priority backlog
Target golang 1.20 https://github.com/golang/go/issues/16100#issuecomment-1320340224