-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
net/http: zombie connection leaked after Server.IdleTimeout #51614
Comments
Setting My interpretation of the http.Server settings here is that once the server sees the first few bytes of the request, instead of being an "idle" connection subject to the "IdleTimeout" setting, the connection instead is considered active and subject to the "ReadHeaderTimeout" setting. |
Yes, // client.go
package main
import (
"log"
"net"
"time"
)
func main() {
go func() {
for i := 1; true; i++ {
// Keep printing alive until the conn is closed and the process exit
time.Sleep(time.Second)
log.Printf("alive %vs", i)
}
}()
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
panic(err)
}
reqData := []byte("POST /echo HTTP/1.1\r\nHost: localhost:8080\r\nContent-Length: 5\r\nAccept-Encoding: gzip\r\n\r\nhello")
// step 1: Send part of the data of a request
_, err = conn.Write(reqData[:4])
if err != nil {
panic(err)
}
// step 2: Recv the first response
// The server will not close the conn and will block here
resData := make([]byte, 1024)
n, err := conn.Read(resData)
if err != nil {
panic(err)
}
log.Printf("resData: \n-----\n%v\n-----\nerror: %v", string(resData[:n]), err)
}
For these two client examples, both need users to set Slow connection attack, the device of the client power off, wifi changed, entering an elevator may cause that the client will never send TCP.FIN to the server, then the conn will never be closed and the goroutine serving the conn will never exit. It seems like the famous frameworks based on Many people use As a default configuration, I think it should not leave this side effect. |
I think if |
Maybe golang itself should leave it to users to set the right configuration, but some frameworks should handle their default configuration. Thanks for your time! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Here are the code that can reproduce it:
What did you expect to see?
The server should close the client conn when the client didn't send all the request data after
Server.IdleTimeout
What did you see instead?
The server didn't close the clien conn
The text was updated successfully, but these errors were encountered: