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

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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办