Golang-TLS握手错误

I am running a https web server in go. I am testing it using a angular web app (Chrome browser) that makes ajax calls to the web server.

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. 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.

I am starting my https server like this:

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().

I am using go 1.5.2.

Any help would be appreciated.

Regards,

Sathya

dpfl37651
dpfl37651 那是远程端口。从随机端口提供http包是没有意义的。
4 年多之前 回复
douaoli5328
douaoli5328 查看有关如何站起服务器的更多周围环境可能会有所帮助-日志记录到传入连接是通过端口:51463记录的事实表明,在代码中的某个地方,stdlibHTTP库正在选择随机端口用于服务流量(443除外)。
4 年多之前 回复
douhui9380
douhui9380 我猜想您和服务器之间会存在一个网络设备,该设备会断开空闲连接,但是您需要进行网络捕获(可能在两侧)以确保。无论如何,您都需要解决网络故障的问题,因此您应该能够解决它。
4 年多之前 回复

1个回答



我启用了tcp keepalive,此问题已解决。 我正在Google计算引擎中运行我的VM,并且防火墙可能终止了空闲连接。</ p>

TCP保持活动 </ p>

在Linux中配置tcp以保持活动状态 </ p>

Golang http服务器自动选择了此功能,因此无需更改我的golang代码。</ p >

致谢</ p>

Sathya </ p>
</ div>

展开原文

原文

I enabled tcp keepalive and this problem got solved. I was running my VM in google compute engine and probably the firewall terminated idle connections.

TCP Keep alive

Configuring tcp keep alive in linux

Golang http server automatically picked this up, so no change was required in my golang code.

Regards,

Sathya

drpiqlzrh62917192
drpiqlzrh62917192 : 谢啦 ! 真的很有帮助
大约一年之前 回复
doujishao8793
doujishao8793 对于任何与Postman进行测试时遇到此问题的人。 您可以在设置中关闭SSL证书验证。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐