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
- func DirFromEnv() (string, error)
- func FindDaemonsForRoot(nmHome string) ([]int, error)
- func MatchesDaemonRoot(pid int, nmHome string) bool
- func MaxConcurrent() (int, error)
- func ProcessAlive(pid int) (bool, error)
- func ReapAbandoned(parent, activeDir string) []error
- type Entry
- type Inventory
- func (inv *Inventory) AcquireSlot(timeout time.Duration) (*Slot, error)
- func (inv *Inventory) List() ([]Entry, error)
- func (inv *Inventory) ReapAll() ReapResult
- func (inv *Inventory) Register(id, nmHome, nmBin string, pid, ownerPID int) error
- func (inv *Inventory) Unregister(id string) error
- func (inv *Inventory) UpdatePID(id string, pid int) error
- type Ownership
- type ReapResult
- type Slot
Constants ¶
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 ¶
DirFromEnv returns the inventory directory from NS_E2E_DAEMON_INVENTORY, or a stable per-user temp default when unset.
func FindDaemonsForRoot ¶
func MatchesDaemonRoot ¶
MatchesDaemonRoot reports whether pid's argv is a no-slop daemon run for exactly the given NS_HOME root (bounded ownership check).
func MaxConcurrent ¶
MaxConcurrent returns the configured concurrency cap.
func ProcessAlive ¶
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 ¶
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 ¶
Open returns an Inventory rooted at DirFromEnv(), creating the directory with mode 0700 when needed.
func (*Inventory) AcquireSlot ¶
AcquireSlot blocks until a concurrency slot is free or timeout elapses. The slot file records the owner pid for diagnostics.
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 ¶
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 ¶
Unregister removes the entry with the given id.
type Ownership ¶
Ownership tracks one harness's inventory entry and concurrency slot.
func Acquire ¶
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.