使用 curl
请求 Go Gin 服务器 curl http://localhost:8000
,响应结果为:
curl: (56) Recv failure: Connection reset by peer
然后,使用 telnet
进行测试 telnet 127.0.0.1 8000
,响应结果为:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
好吧,连接被主机关闭了。为什么呢?应该是主机配置有问题!
再次检查创建服务器的代码:
s := &http.Server{
Addr: fmt.Sprintf(":%d", 8000),
Handler: router,
ReadTimeout: 60, // !!!
WriteTimeout: 60, // !!!
MaxHeaderBytes: 1 << 20,
}
ReadTimeout
和 WriteTimeout
的值,其实都是 60 纳秒!
应该改为:
60 * time.Second
因为,time.Duration
是 1 纳秒(nanosecond)!
具体定义,请参考 time 包中的源码:
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
)
参考内容:
https://github.com/gin-gonic/gin/issues/1556#issuecomment-446561126
觉得不错?点个赞呗~
本文链接:Go Gin curl: (56) Recv failure: Connection reset by peer
转载声明:本站文章如无特别说明,皆为原创。转载请注明:Ficow Shen's Blog