Golang how to handle gracefull shutdown with keep alives

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?

Upvotes: 1

Views: 912

Answers (1)

Mr_Pink
Mr_Pink

Reputation: 109347

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.

Upvotes: 2

Related Questions