fatal

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package fatal provides a way to handle fatal errors.

  1. It gives the main goroutine an opportunity to cleanly shut down in case of a fatal error.
  2. If main goroutine is non-responsive it terminates the process.
  3. To improve debugging, after the first fatal error the other goroutines are given a grace period so that we have more logs to investigate.

Also implemented is a clean shutdown option, for non-error events that trigger clean application shutdown (e.g., a signal received from the user).

The main program should call fatal.Init() when it's starting.

Any library producing fatal errors should call fatal.Check() when it starts.

Index

Constants

View Source
const (
	// FatalDelayInterval is the interval between when a package signals that a
	// fatal event has occurred, and when drainers of the fatal channel are
	// informed. This allows for collecting more informative logs before
	// tearing the application down.
	FatalDelayInterval = time.Second
	// FatalGraceInterval is the time in which the main goroutine should shut
	// the application down.
	FatalGraceInterval = 5 * time.Second
)

Variables

This section is empty.

Functions

func Check

func Check()

Check checks whether the package was initialized. This MUST be called when a library producing fatal errors starts is initialized.

func Fatal

func Fatal(err error)

Fatal produces a fatal error. This function never exits.

func FatalChan

func FatalChan() <-chan struct{}

FatalChan returns a read-only channel that is closed when a fatal condition has occurred.

func Init

func Init()

Init Initializes the package. This MUST be called in the main coroutine when it starts.

func Shutdown

func Shutdown(d time.Duration)

Shutdown closes the shutdown channel, thus informing channel drainers (usually the main goroutine) that the application should be cleanly shut down. If the application does not shut down in the specified duration, it is forcefully torn down.

Shutdown blocks forever.

func ShutdownChan

func ShutdownChan() <-chan struct{}

ShutdownChan returns a read-only channel that is closed when the application should be cleanly shut down.

Types

This section is empty.

Jump to

Keyboard shortcuts

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