graceful

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2015 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package graceful implements graceful shutdown for HTTP servers by closing idle connections after receiving a signal. By default, this package listens for interrupts (i.e., SIGINT), but when it detects that it is running under Einhorn it will additionally listen for SIGUSR2 as well, giving your application automatic support for graceful restarts/code upgrades.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSignal

func AddSignal(sig ...os.Signal)

AddSignal adds the given signal to the set of signals that trigger a graceful shutdown.

func DoubleKickWindow added in v0.8.3

func DoubleKickWindow(d time.Duration)

DoubleKickWindow sets the length of the window during which two back-to-back signals are treated as an especially urgent or forceful request to exit (i.e., ShutdownNow instead of Shutdown). Signals delivered more than this duration apart are treated as separate requests to exit gracefully as usual.

Setting DoubleKickWindow to 0 disables the feature.

func HandleSignals

func HandleSignals()

HandleSignals installs signal handlers for a set of standard signals. By default, this set only includes keyboard interrupts, however when the package detects that it is running under Einhorn, a SIGUSR2 handler is installed as well.

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

ListenAndServe behaves exactly like the net/http function of the same name.

func ListenAndServeTLS

func ListenAndServeTLS(addr, certfile, keyfile string, handler http.Handler) error

ListenAndServeTLS behaves almost exactly like the net/http function of the same name. Unlike net/http, however, this function defaults to enforcing TLS 1.0 or higher in order to address the POODLE vulnerability. Users who wish to enable SSLv3 must do so by explicitly instantiating a server with an appropriately configured TLSConfig property.

func PostHook

func PostHook(f func())

PostHook registers a function to be called after all of this package's normal shutdown actions. All listeners will be called in the order they were added, from a single goroutine, and are guaranteed to be called after all listening connections have been closed, but before Wait() returns.

If you've Hijacked any connections that must be gracefully shut down in some other way (since this library disowns all hijacked connections), it's reasonable to use a PostHook to signal and wait for them.

func PreHook

func PreHook(f func())

PreHook registers a function to be called before any of this package's normal shutdown actions. All listeners will be called in the order they were added, from a single goroutine.

func ResetSignals

func ResetSignals()

ResetSignals resets the list of signals that trigger a graceful shutdown.

func Serve

func Serve(l net.Listener, handler http.Handler) error

Serve behaves exactly like the net/http function of the same name.

func Shutdown

func Shutdown()

Shutdown manually triggers a shutdown from your application. Like Wait, blocks until all connections have gracefully shut down.

func ShutdownNow added in v0.8.3

func ShutdownNow()

ShutdownNow triggers an immediate shutdown from your application. All connections (not just those that are idle) are immediately closed, even if they are in the middle of serving a request.

func Timeout added in v0.8.3

func Timeout(d time.Duration)

Timeout sets the maximum amount of time package graceful will wait for connections to gracefully shut down after receiving a signal. After this timeout, connections will be forcefully shut down (similar to calling ShutdownNow).

Setting Timeout to 0 disables the feature.

func Wait

func Wait()

Wait for all connections to gracefully shut down. This is commonly called at the bottom of the main() function to prevent the program from exiting prematurely.

func WrapListener

func WrapListener(l net.Listener) net.Listener

WrapListener wraps an arbitrary net.Listener for use with graceful shutdowns. In the background, it uses the listener sub-package to Wrap the listener in Deadline mode. If another mode of operation is desired, you should call listener.Wrap yourself: this function is smart enough to not double-wrap listeners.

Types

type Server

type Server http.Server

Type Server is exactly the same as an http.Server, but provides more graceful implementations of its methods.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

Unlike the method of the same name on http.Server, this function defaults to enforcing TLS 1.0 or higher in order to address the POODLE vulnerability. Users who wish to enable SSLv3 must do so by supplying a TLSConfig explicitly.

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Directories

Path Synopsis
Package listener provides a way to incorporate graceful shutdown to any net.Listener.
Package listener provides a way to incorporate graceful shutdown to any net.Listener.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL