signals

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package signals coordinates process-wide signal handling behavior.

Atmos installs a global SIGINT/SIGTERM handler in main() that exits the process. When a step hands the terminal to a foreground child process (interactive or TTY steps), Ctrl-C must be handled by the child, not by Atmos: the terminal delivers SIGINT to the whole foreground process group, and if Atmos exits first the child is killed by SIGPIPE mid-session.

This package provides a nestable suspension counter that the main signal handler consults before exiting on SIGINT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginGracefulStop

func BeginGracefulStop(sig os.Signal) ([]string, bool)

BeginGracefulStop handles sig with the process-wide registry; see GracefulStops.Begin.

func CleanupExitDeferred

func CleanupExitDeferred() bool

CleanupExitDeferred reports whether bounded credential cleanup owns shutdown.

func DeferExitForCleanup

func DeferExitForCleanup(ctx context.Context) (context.Context, func())

DeferExitForCleanup cancels an operation on SIGINT/SIGTERM while letting its owner finish bounded credential cleanup before main's immediate exit path. The owner must release the scope after cleanup, including error paths.

func ExitRequested

func ExitRequested() bool

ExitRequested reports a retained shutdown request, including after scopes drain.

func GracefulStopNotice

func GracefulStopNotice(sig os.Signal, names []string) string

GracefulStopNotice tells the user that Atmos is waiting for the named commands to stop after the first signal, and how to force the exit.

func InterruptContext

func InterruptContext(parent context.Context) (ctx context.Context, stop context.CancelFunc)

InterruptContext returns a context that is canceled when SIGINT or SIGTERM arrives, like signal.NotifyContext. Its cancellation cause wraps errUtils.ErrSignalReceived, so a subprocess runner can tell an interrupt (which a graceful child handles itself) from a timeout or another cancellation (which still terminates the child). Call stop to release the signal listener.

func InterruptExitSuspended

func InterruptExitSuspended() bool

InterruptExitSuspended reports whether the process-exit-on-SIGINT behavior is currently suspended because a foreground child process owns SIGINT.

func InterruptedBySignal

func InterruptedBySignal(ctx context.Context) bool

InterruptedBySignal reports whether ctx was canceled because Atmos received SIGINT or SIGTERM through InterruptContext, including through derived contexts.

func OwnedCleanupContext

func OwnedCleanupContext(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

OwnedCleanupContext retains custody of a credential acquisition or release after caller cancellation. Native plugin supervision honors this bounded host-owned context instead of independently killing it on the same signal.

func OwnsCleanup

func OwnsCleanup(ctx context.Context) bool

OwnsCleanup is host-only context metadata, never plugin-controlled settings.

func RegisterExitCleanup

func RegisterExitCleanup(cleanup func()) (deregister func())

RegisterExitCleanup registers a cleanup to run if the process exits through the signal handler. The returned deregister function removes it (idempotent) and must be called when the cleanup has been performed normally.

func RequestExit

func RequestExit(received os.Signal)

RequestExit retains the first signal and cancels every active operation. A command that catches a per-secret error cannot turn interruption into success.

func ResolveExitCode

func ResolveExitCode(fallback int) int

ResolveExitCode preserves interruption even if command code swallowed an error or raced the main signal handler after finishing its final cleanup. After an interrupt it first waits for graceful children (for example Terraform saving state) to exit, so returning early cannot trigger exit cleanup that kills them.

func RunExitCleanups

func RunExitCleanups()

RunExitCleanups runs all registered exit cleanups (most recent first). Called by the main signal handler before exiting the process.

func SuspendInterruptExit

func SuspendInterruptExit() (release func())

SuspendInterruptExit marks that a foreground child process owns SIGINT handling. It returns a release function that must be called when the child exits. Suspensions nest (e.g., a workflow TTY step inside a custom command), and the release function is idempotent.

func WaitForCleanup

func WaitForCleanup() bool

WaitForCleanup waits before plugin/process exit cleanup kills owned issuers. The bound also covers an operation that fails to honor cancellation.

Types

type GracefulStops

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

GracefulStops coordinates child processes that must stop on their own when Atmos is interrupted, such as Terraform saving state and releasing its lock.

The first SIGINT/SIGTERM is forwarded once to every registered child and the exit is deferred until they have all exited. A second signal forces the exit: the caller then runs the usual exit cleanups, which terminate the children.

func DefaultGracefulStops

func DefaultGracefulStops() *GracefulStops

DefaultGracefulStops returns the registry used by the Atmos signal handler.

func NewGracefulStops

func NewGracefulStops(onBegin func(os.Signal), onDrain func()) *GracefulStops

NewGracefulStops returns an empty registry. The optional onBegin runs once when a graceful stop begins, before the signal is forwarded; onDrain runs once when the last child of a begun stop exits.

func (*GracefulStops) Begin

func (g *GracefulStops) Begin(sig os.Signal) ([]string, bool)

Begin handles a SIGINT/SIGTERM that would otherwise exit Atmos. When children are registered and no stop is in progress, it retains sig through onBegin, forwards sig once to every child, and returns their sorted display names with true: the caller must then keep running and wait. Otherwise it returns false and the caller exits; a signal received during a stop also forces Wait to return.

func (*GracefulStops) Register

func (g *GracefulStops) Register(name string, forward func(os.Signal)) (release func())

Register records a running child under a display name. The forward function delivers the first signal to the child; it is called at most once. A child registered after a stop began receives that signal immediately. The returned release function must be called once the child has exited; it is idempotent.

func (*GracefulStops) Stopping

func (g *GracefulStops) Stopping() bool

Stopping reports whether a graceful stop has begun. New graceful children must not start once it has.

func (*GracefulStops) Wait

func (g *GracefulStops) Wait()

Wait blocks until every registered child has exited or a second signal forced the exit. It is deliberately unbounded, like Terraform's own wait after the first interrupt: an in-flight resource may take minutes to finish, and the second signal is the escape hatch.

Jump to

Keyboard shortcuts

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