douguanya4248
2014-09-18 18:49
浏览 197
已采纳

Golang如何使用Keepalive处理正常关机

I have build a proxy server that can balance between multiple nodes. I also made it that it can reload with zero downtime. Problem is that most of the nodes have keep alive connections and i have no clue how to handle these. Sometimes the server cant shutdown off 1 or 2 open connections that wont close.

My first opinion is to set a timeout on the shutdown but that does not secures me that every connection is terminated correctly. I think of a download that takes some minutes to complete.

Anyone can give me some good advise what to do in this case?

图片转代码服务由CSDN问答提供 功能建议

我已经建立了一个代理服务器,可以在多个节点之间进行平衡。 我还使其可以零加载。 停机时间。 问题是大多数节点都保持活动连接,并且我不知道如何处理这些连接。 有时服务器无法关闭1或2个不会关闭的打开的连接。

我的第一意见是在关机时设置超时,但这不能确保每个连接都正确终止。 我认为下载需要几分钟才能完成。

在这种情况下,任何人都可以给我一些很好的建议。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanqinjiao5244 2014-09-18 18:59
    已采纳

    One option you have is to initially shutdown just the listening sockets, and wait on the active connections before exiting.

    Once you free up the listening sockets, your new process is free to start up and accept new connections. The old process can then continue running until all its connections are closed gracefully (this is how HAProxy does reloads), or until some far longer timeout if you choose.

    点赞 评论

相关推荐 更多相似问题