Golang Server Graceful Downtime

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.