简体   繁体   English

Golang - TLS 握手错误

[英]Golang - TLS handshake error

I am running a https web server in go.我正在运行一个 https Web 服务器。 I am testing it using a angular web app (Chrome browser) that makes ajax calls to the web server.我正在使用对 Web 服务器进行 ajax 调用的角度 Web 应用程序(Chrome 浏览器)对其进行测试。

If I keep hitting the web server continuously everything seems working.如果我不断地访问网络服务器,一切似乎都正常。 But whenever I leave it idle for sometime and hit the web server the ajax call from browser doesn't get a response.但是每当我让它闲置一段时间并访问 Web 服务器时,来自浏览器的 ajax 调用就不会得到响应。 Almost always I see this log line in my server log.我几乎总是在我的服务器日志中看到这个日志行。

2016/01/16 04:06:47.006977 http: TLS handshake error from 42.21.139.47:51463: EOF

I can confirm that the IP address is my IP address.我可以确认IP地址是我的IP地址。

I am starting my https server like this:我正在这样启动我的 https 服务器:

r := mux.NewRouter()
r.HandleFunc("/status", handleStatus)
setUpLoginEndpoint(&cfg.Session, r)
setUpLogoutEndpoint(cfg.Session.CookieName, r)
setUpChangePasswordEndpoint(cfg.Session.CookieName, r)
setUpMetricSinkEndpoint(cfg.Metric.SinkApiKey, r)
setUpMetricQueryEndpoint(cfg.Session.CookieName, r)
http.ListenAndServeTLS(":443", "../cert.pem", "../keys.pem", &Server{r})

I can confirm that I am closing the request body in every handler using defer r.Body.Close().我可以确认我正在使用 defer r.Body.Close() 关闭每个处理程序中的请求主体。

I am using go 1.5.2.我正在使用 1.5.2。

Any help would be appreciated.任何帮助,将不胜感激。

Regards,问候,

Sathya沙迪亚

I enabled tcp keepalive and this problem got solved.我启用了 tcp keepalive,这个问题就解决了。 I was running my VM in google compute engine and probably the firewall terminated idle connections.我在谷歌计算引擎中运行我的虚拟机,可能是防火墙终止了空闲连接。

TCP Keep alive TCP保持活跃

Configuring tcp keep alive in linux 在linux中配置tcp keep alive

Golang http server automatically picked this up, so no change was required in my golang code. Golang http 服务器自动拾取它,因此我的 golang 代码不需要更改。

Regards,问候,

Sathya沙迪亚

I was receiving the same error as OP, but in my case the TLSHandshakeTimeout value I was specifying was too low.我收到了与 OP 相同的错误,但就我而言,我指定的 TLSHandshakeTimeout 值太低。 I'm not sure what an appropriate value is but moving it to 700ms from 100ms eliminated the error for me.我不确定什么是合适的值,但将它从 100 毫秒移至 700 毫秒消除了我的错误。 For others experiencing the same error and who are specifying non-default http.Transport config values in their http.Client setup, you might want to make sure your TLSHandshakeTimeout is set to a high enough value.对于遇到相同错误并且在其 http.Client 设置中指定非默认 http.Transport 配置值的其他人,您可能需要确保将 TLSHandshakeTimeout 设置为足够高的值。

&http.Client{
  Transport: &http.Transport{
    TLSHandshakeTimeout:   700 * time.Millisecond, //<-- I was receiving OP's error when I had this set to 100ms
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM