antifreeze

package module
v0.0.0-...-b207abe Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Unlicense Imports: 9 Imported by: 0

README

antifreeze

antifreeze is a package that detects goroutines that have been waiting for too long.

Warning: this package is alpha and may not work as intended.

You can exclude functions that may block forever with antifreeze.Exclude and antifreeze.ExcludeNamed.

Example program that will panic ~1min after you have made a request to it.

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/egonelbre/antifreeze"
)

func init() {
	antifreeze.SetFrozenLimit(1 * time.Minute)
}

var ch = make(chan int)

func runner() {
	antifreeze.Exclude()
	<-ch
}

func main() {
	go runner()
	http.Handle("/", http.HandlerFunc(index))
	http.ListenAndServe(":8000", nil)
}

func index(w http.ResponseWriter, r *http.Request) {
	fmt.Println("R:", r)
	<-ch
}

See godoc for more information.

Documentation

Index

Constants

View Source
const (
	// DefaultBufferSize specifies how much buffer to use for reading stack
	// profiles by default.
	DefaultBufferSize = 8 << 20
	// DefaultFrozenLimit specifies when a goroutine should be considered stuck.
	DefaultFrozenLimit = 10 * time.Minute
)

Variables

This section is empty.

Functions

func Exclude

func Exclude()

Exclude excludes all goroutines that contain current function in the callstack.

func ExcludeNamed

func ExcludeNamed(name string)

ExcludeNamed excludes all goroutines that contain the named func The func name must be fully qualified.

antifreeze.ExcludeNamed("main.runner")
antifreeze.ExcludeNamed("net/http.ListenAndServe")
antifreeze.ExcludeNamed("net.(*pollDesc).Wait")

func SetBufferSize

func SetBufferSize(size int)

SetBufferSize sets the maximum buffer size for reading stack profiles. Set this lower, e.g. 1<<10 (10MB) to reduce memory footprint at the cost of possibly not tracking some goroutines. Set it higher, e.g. 64<<10 (64MB) if you expect a lot of goroutines.

func SetFrozenLimit

func SetFrozenLimit(limit time.Duration)

SetFrozenLimit sets the limit after which the goroutine should be considered as frozen.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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