guard

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package guard bounds a native host process of the conformance gate: a request that runs too long, a heap that grows past a limit, or a parent that has gone. A core step is a synchronous call, so a step that never returns (a scheduler loop with no hop to the host) also never lets its parent time out: the parent blocks in a read, the gate kills the parent, and the child keeps allocating until the host is out of memory. The guard ends the child itself, names the request and writes the stack of every goroutine, so the row fails with its cause. Host processes only; no core package imports it.

Index

Constants

View Source
const (
	EnvMemoryMB = "DCORE_CORE_MEM_LIMIT_MB"
	EnvStepSecs = "DCORE_CORE_STEP_TIMEOUT_S"
)

Environment variables a gate run passes to the child (the gate forwards DCORE_*).

View Source
const (
	ExitBound  = 3
	ExitParent = 4
)

Exit codes of a tripped guard. ExitBound is a runaway (reported on stderr); ExitParent is silent.

View Source
const (
	DefaultMemoryMB = 2 * 1024
	DefaultStepSecs = 120
)

Default bounds. The largest legitimate request (a cold open of the 3500-turn history) takes seconds and a few hundred MiB (W1-3500 stays under 384 MiB); four parallel hosts stay inside a lane's 12 GB.

Variables

This section is empty.

Functions

This section is empty.

Types

type Guard

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

Guard watches one process.

func Start

func Start(o Options) *Guard

Start begins watching. The watcher is a goroutine of the host process; call Stop to end it.

func (*Guard) Begin

func (g *Guard) Begin(what string)

Begin marks a request as running; End marks it done. Only a running request is timed.

func (*Guard) End

func (g *Guard) End()

End marks the running request done.

func (*Guard) Stop

func (g *Guard) Stop()

Stop ends the watcher. A second call does nothing.

type Options

type Options struct {
	Name        string        // the process, for messages
	MemoryBytes uint64        // the most the Go runtime may hold from the system
	Step        time.Duration // the longest one request may run
	Parent      int           // the parent process ID; the process ends when it changes (re-parented to init)
	Poll        time.Duration // how often the bounds are checked (default 100 ms)
	Exit        func(code int)
	Stderr      io.Writer
}

Options of a Guard. A zero field disables that bound.

func FromEnv

func FromEnv(name string) Options

FromEnv is the options a gate run sets in the environment, with the defaults above.

Jump to

Keyboard shortcuts

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