chanlock

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT, Apache-2.0 Imports: 16 Imported by: 0

README

chanlock

This is a fork of some aspects of go-deadlock, a library for diagnosing locking issues with mutexes. It repurposes the deadlock detection mechanism for use with Go code that uses the for { select { ... } } pattern.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Opts = struct {
	// -- almost no runtime penalty, no deadlock detection if Disable == true.
	Disable bool
	// Waiting for a lock for longer than DeadlockTimeout is considered a deadlock.
	// Ignored if DeadlockTimeout <= 0.
	DeadlockTimeout time.Duration
	// The rate at which chanlock's ticker executes.
	HealthCheckRate time.Duration
	// OnPotentialDeadlock is called each time a potential deadlock is detected -- either based on
	// lock order or on lock wait time.
	OnPotentialDeadlock func()
	// Will keep MaxMapSize lock pairs (happens before // happens after) in the map.
	// The map resets once the threshold is reached.
	MaxMapSize int
	// Will dump stacktraces of all goroutines when inconsistent locking is detected.
	PrintAllCurrentGoroutines bool
	mu                        *sync.Mutex // Protects the LogBuf.
	// Will print deadlock info to log buffer.
	LogBuf io.Writer
}{
	DeadlockTimeout: time.Second * 30,
	HealthCheckRate: time.Second * 1,
	OnPotentialDeadlock: func() {
		os.Exit(2)
	},
	MaxMapSize: 1024 * 64,

	LogBuf: os.Stderr,
	// contains filtered or unexported fields
}

Opts control how deadlock detection behaves. Options are supposed to be set once at a startup (say, when parsing flags).

Functions

This section is empty.

Types

type Chanlock

type Chanlock struct {
	// contains filtered or unexported fields
}

Utility for diagnosing channel lock.

func New

func New() *Chanlock

func (*Chanlock) Poll

func (c *Chanlock) Poll(ctx context.Context) <-chan time.Time

Jump to

Keyboard shortcuts

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