我正在运行一个https Web服务器。我正在使用可对Web服务器进行Ajax调用的有角度的Web应用程序(Chrome浏览器)对其进行测试。
如果我持续不断地访问Web服务器,那么一切似乎都可以正常工作。但是,每当我将其闲置一段时间并访问Web服务器时,来自浏览器的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})
Run Code Online (Sandbox Code Playgroud)
我可以确认是否使用defer r.Body.Close()关闭每个处理程序中的请求主体。
我正在使用1.5.2。
任何帮助,将不胜感激。
问候,
萨提亚
我启用了tcp keepalive,此问题已解决。我在Google计算引擎中运行我的VM,并且防火墙可能终止了空闲连接。
Golang http服务器会自动选择此代码,因此无需更改我的golang代码。
问候,
萨提亚