Server.Shutdown

The http.Server method that stops accepting new connections and waits for active requests to finish, up to the deadline of the context you pass.

In more detail

Call it after receiving SIGTERM, with a context from context.WithTimeout that fits inside the orchestrator's grace period. It returns the context's error if the deadline passes first, which you should report. After it returns, ListenAndServe returns http.ErrServerClosed.

Example

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := server.Shutdown(ctx)

Related terms

Taught in

References