This time write in Chinese, express clearly.
Recently saw a few procedures, combined with their own thinking, give the Golang service its graceful shutdown processing way. The HTTP server is described here as an object.
Here the "elegance", indicating that the server has a plan, step-by-step exit. Specifically, it terminates the connection with the client, closes the process of other activities, threads, and completes the release of the resource; complete log.
1. Classification
Server outages can be divided into two categories: Server active downtime and server passive downtime.
1) Server active shutdown, that is, in the absence of external impact (client calls), the server spontaneously stopped. Timed outages, and idle timeout outages are common scenarios. Below I mainly describe the idle timeout shutdown to describe.
2) Server passive shutdown, that is, under the influence of external conditions (external command control, external function call), the server stopped. Two scenarios are discussed here: Client request and Function call.
2. The following example describes two types of outages using the Golang socket server.
1) Server Active shutdown-idle Timeout
2) Passive server shutdown
2.1) Client Sending Requet
2.2) The Stop () function explicitly calls the
Golang Server Graceful Downtime