Closed AprilYoLies closed 1 year ago
This was fixed in https://github.com/valyala/fasthttp/commit/8cc5539af71f1f944d81365c7bccc2958ded0a7f I'll tag a release for this tomorrow.
By default, the internal logic of fasthttp retries five times. Therefore, the result takes five times as long as the timeout period.
client = &fasthttp.Client{
MaxIdemponentCallAttempts: 1,
MaxIdleConnDuration: 10 * time.Second,
MaxConnsPerHost: 10240,
ReadTimeout: 2 * time.Second,
WriteTimeout: time.Duration(30) * time.Second,
ReadBufferSize: 6 * 1024,
Dial: func(addr string) (net.Conn, error) {
return tcpDialer.DialTimeout(addr, 2*time.Second)
},
}
Use this variable MaxIdemponentCallAttempts: 1
to control the number of retries, and if you set the number of retries to 1, the result is as expected.
server.go
client.go
And I hope client.DoTimeout method can return in 200ms, however it return in one second. If I given the timeout with 400ms, client.DoTimeout method will return in two second.