英文:
Golang how to handle gracefull shutdown with keep alives
问题
我已经构建了一个能够在多个节点之间进行负载均衡的代理服务器。
我还使其能够在零停机时间下重新加载。问题是大多数节点都有保持活动连接,而我不知道如何处理这些连接。有时服务器无法关闭1或2个不关闭的打开连接。
我的第一个想法是在关闭时设置一个超时时间,但这不能确保每个连接都正确终止。我考虑到一个需要几分钟才能完成的下载。
有人可以给我一些建议,应该在这种情况下怎么做吗?
英文:
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?
答案1
得分: 2
你有一个选择,那就是在退出之前,首先关闭监听套接字,并等待活动连接。
一旦释放了监听套接字,你的新进程就可以自由地启动并接受新的连接。旧进程可以继续运行,直到所有连接都被优雅地关闭(这是HAProxy进行重新加载的方式),或者选择一个更长的超时时间。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论