e2edaemon

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package e2edaemon owns isolated temporary no-mistakes process lifecycle: exact inventory, a reaper with bounded ownership checks, and a concurrency slot cap.

Scope includes temporary E2E daemons (NS_TEST_START_DAEMON detached starts under harness temp roots) and eval candidate roots. The shared production daemon and external sleep-loop keepalive shells are out of scope.

Recovery boundary (honest):

  • t.Cleanup and package TestMain reapers cover normal completion and most interrupt paths that leave the Go process able to run cleanups.
  • scripts/e2e.sh traps EXIT/INT/TERM on the suite wrapper shell so a killed or timed-out go-test child still gets inventory reaped.
  • A SIGKILL of that same wrapper shell does NOT run its EXIT trap. Stale inventory on disk is recovered on the next suite start (TestMain + wrapper pre-reap). Do not claim shell traps survive SIGKILL of the trapping shell.

Index

Constants

View Source
const (
	// EnvInventory is the absolute path to the suite inventory directory.
	// When unset, a process-local default under the system temp dir is used.
	EnvInventory       = "NS_E2E_DAEMON_INVENTORY"
	LegacyEnvInventory = "NM_E2E_DAEMON_INVENTORY"

	// EnvMaxConcurrent caps how many temporary E2E daemons may be live at once.
	EnvMaxConcurrent       = "NS_E2E_DAEMON_MAX"
	LegacyEnvMaxConcurrent = "NM_E2E_DAEMON_MAX"

	// DefaultMaxConcurrent bounds blast radius of one interrupted suite.
	DefaultMaxConcurrent = 2
)

Variables

This section is empty.

Functions

func DirFromEnv

func DirFromEnv() (string, error)

DirFromEnv returns the inventory directory from NS_E2E_DAEMON_INVENTORY, or a stable per-user temp default when unset.

func FindDaemonsForRoot

func FindDaemonsForRoot(nmHome string) ([]int, error)

func MatchesDaemonRoot

func MatchesDaemonRoot(pid int, nmHome string) bool

MatchesDaemonRoot reports whether pid's argv is a no-slop daemon run for exactly the given NS_HOME root (bounded ownership check).

func MaxConcurrent

func MaxConcurrent() (int, error)

MaxConcurrent returns the configured concurrency cap.

func ProcessAlive

func ProcessAlive(pid int) (bool, error)

ProcessAlive reports whether pid is still a live process. It is a single cheap OS probe (no `ps` subprocess), which is what lets a test observe process state at the instant a command returns rather than milliseconds later.

func ReapAbandoned

func ReapAbandoned(parent, activeDir string) []error

Types

type Entry

type Entry struct {
	ID           string    `json:"id"`
	NMHome       string    `json:"nm_home"`
	PID          int       `json:"pid"`
	NMBin        string    `json:"nm_bin,omitempty"`
	ProcessHash  string    `json:"process_hash,omitempty"`
	OwnerPID     int       `json:"owner_pid"`
	RegisteredAt time.Time `json:"registered_at"`
}

Entry is one owned temporary E2E daemon root.

type Inventory

type Inventory struct {
	Dir string
	// contains filtered or unexported fields
}

Inventory is a process-safe, file-backed record of temporary E2E daemons.

func Open

func Open() (*Inventory, error)

Open returns an Inventory rooted at DirFromEnv(), creating the directory with mode 0700 when needed.

func OpenDir

func OpenDir(dir string) (*Inventory, error)

OpenDir opens (or creates) an inventory directory.

func (*Inventory) AcquireSlot

func (inv *Inventory) AcquireSlot(timeout time.Duration) (*Slot, error)

AcquireSlot blocks until a concurrency slot is free or timeout elapses. The slot file records the owner pid for diagnostics.

func (*Inventory) List

func (inv *Inventory) List() ([]Entry, error)

List returns a snapshot of inventory entries.

func (*Inventory) ReapAll

func (inv *Inventory) ReapAll() ReapResult

ReapAll stops every inventoried temporary daemon with bounded ownership checks, then removes their inventory entries. It never touches processes that are not listed in the inventory or whose argv no longer matches the recorded NS_HOME (so the shared service is never a target).

func (*Inventory) Register

func (inv *Inventory) Register(id, nmHome, nmBin string, pid, ownerPID int) error

Register records or updates ownership for nmHome. pid may be 0 when the daemon has not started yet; SyncPID upgrades it later.

func (*Inventory) Unregister

func (inv *Inventory) Unregister(id string) error

Unregister removes the entry with the given id.

func (*Inventory) UpdatePID

func (inv *Inventory) UpdatePID(id string, pid int) error

UpdatePID sets the recorded pid for id (or nmHome match).

type Ownership

type Ownership struct {
	Inv    *Inventory
	ID     string
	NMHome string
	NMBin  string
	Slot   *Slot
}

Ownership tracks one harness's inventory entry and concurrency slot.

func Acquire

func Acquire(nmHome, nmBin string, slotTimeout time.Duration) (*Ownership, error)

Acquire creates inventory ownership for a temp NS_HOME under the suite concurrency cap. Call SyncPID after the daemon becomes live; call Release after stop (or from the reaper path).

func (*Ownership) Release

func (o *Ownership) Release()

Release stops best-effort, reaps any leftover matched process for this home only, and frees the slot. Inconclusive cleanup remains inventoried.

func (*Ownership) StopBestEffort

func (o *Ownership) StopBestEffort()

StopBestEffort runs daemon stop for this home when a binary is known.

func (*Ownership) SyncPID

func (o *Ownership) SyncPID(pid int) error

SyncPID reads a live daemon pid (from caller) into the inventory.

func (*Ownership) SyncProcess

func (o *Ownership) SyncProcess(pid int) error

type ReapResult

type ReapResult struct {
	Entries int
	Stopped int
	Killed  int
	Removed int
	Skipped int
	Errors  []string
}

ReapResult summarizes one reaper pass.

type Slot

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

Slot is a held concurrency permit for one temporary E2E daemon owner.

func (*Slot) Release

func (s *Slot) Release()

Release frees the concurrency slot.

Jump to

Keyboard shortcuts

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