我正在 go 中运行 https Web 服务器。我正在使用一个有角度的网络应用程序(Chrome 浏览器)来测试它,该应用程序向网络服务器发出 ajax 调用。
如果我不断地访问网络服务器,一切似乎都正常。但是每当我让它闲置一段时间并访问网络服务器时,来自浏览器的 ajax 调用就不会得到响应。我几乎总是在服务器日志中看到此日志行。
2016/01/16 04:06:47.006977 http: TLS handshake error from 42.21.139.47:51463: EOF
我可以确认该IP地址是我的IP地址。
我像这样启动我的 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})
我可以确认我正在使用 defer r.Body.Close() 关闭每个处理程序中的请求正文。
我正在使用 go 1.5.2。
任何帮助,将不胜感激。
Regards,
Sathya
我启用了tcp keepalive,这个问题就解决了。我在谷歌计算引擎中运行我的虚拟机,防火墙可能终止了空闲连接。
TCP 保持活动状态 http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html
在Linux中配置tcp keep-alive http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html
Golang http 服务器会自动识别此内容,因此不需要对我的 golang 代码进行任何更改。
Regards,
Sathya
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)