Make SIGTERM timeout configurable via --sigterm-timeout and GLUETOOL_SIGTERM_TIMEOUT

Summary

The time gluetool waits for a child process to exit after sending it SIGTERM, before resorting to SIGKILL, was hardcoded to DEFAULT_SIGTERM_TIMEOUT (60 seconds).

This MR makes it configurable, resolved with the following precedence:

  1. the sigterm-timeout option — set on the command line (--sigterm-timeout) or in a configuration file,
  2. the GLUETOOL_SIGTERM_TIMEOUT environment variable, following the existing GLUETOOL_TRACING_* convention,
  3. DEFAULT_SIGTERM_TIMEOUT (60s) when neither is set.

Changes

  • Added the SIGTERM_TIMEOUT_ENVVAR = 'GLUETOOL_SIGTERM_TIMEOUT' constant.
  • Added a module-level sigterm_timeout(glue=None) helper that resolves the value following the precedence above. When a Glue instance is passed it reads the sigterm-timeout option from it; otherwise the option is skipped.
  • Added the sigterm-timeout gluetool option (type: int, default: None) so the timeout can be set on the command line or in a configuration file.
  • The child.wait(...) call in the SIGTERMSIGKILL escalation now uses sigterm_timeout(Glue) instead of the constant directly.
  • Documented GLUETOOL_SIGTERM_TIMEOUT in the --help epilog alongside the other supported environment variables.

Usage

# via the command-line option (takes precedence)
gluetool --sigterm-timeout 120 ...

# via a configuration file
# [default]
# sigterm-timeout = 120

# via the environment variable
export GLUETOOL_SIGTERM_TIMEOUT=120   # wait 120s before sending SIGKILL

Tests

  • test_sigterm_timeout_default — falls back to DEFAULT_SIGTERM_TIMEOUT when neither the option nor the env var is set.
  • test_sigterm_timeout_envvar (parametrized: 0, 1, 120) — env var overrides the default.
  • test_sigterm_timeout_envvar_invalid — a non-numeric env var raises ValueError.
  • test_sigterm_timeout_option_overrides_envvar — the option takes precedence over the env var.
  • test_sigterm_timeout_option_unset_falls_back_to_envvar — the env var is used when the option is unset.
  • test_sigterm_timeout_option_unset_falls_back_to_default — the default is used when neither is set.
  • test_sigterm_timeout_option_from_cmdline — the option is wired into the command-line parser and parsed as an integer.
Edited by Miroslav Vadkerti

Merge request reports

Loading