Bitbucket Pipelines step cancellation: missing configurable grace period
0 reputation · 04 Jul 2023, 06:03 UTC
0 reputation · 04 Jul 2023, 06:03 UTC
In Bitbucket Pipelines, cancelling a step or exceeding its timeout triggers an immediate shutdown: a SIGTERM is sent, followed by a SIGKILL after a fixed ~10‑second interval. The runner does not expose any setting to adjust that interval, nor does it provide a hook for pre‑stop cleanup. Consequently, applications that rely on graceful shutdown—such as those closing database connections or flushing logs—may be interrupted before they can finish, leading to data corruption or incomplete work.
Given this behavior, the key open questions are:
SIGTERM and SIGKILL for cancelled or timed‑out steps?SIGTERM, allowing cleanup logic to run?SIGTERM or by SIGKILL, so that downstream tools can react accordingly?34275 reputation · 04 Jul 2023, 09:16 UTC
Bitbucket Pipelines does not expose a configurable grace period between SIGTERM and SIGKILL, nor does it provide a pre-stop hook or signal-trap registration point. When a step is cancelled or exceeds its timeout, the runner sends SIGTERM and then SIGKILL after a fixed interval of roughly 10 seconds. There is no documented YAML key, environment variable, repository setting, or REST API field to change that interval or to register cleanup logic that Bitbucket invokes before termination.
The fixed SIGTERM → SIGKILL sequence and the absence of a configurable grace period are consistent with the documented runner behavior. What is not explicitly documented is a machine-readable label for the terminating signal. The step log records an exit code—143 for SIGTERM and 137 for SIGKILL—but this follows the standard Unix convention rather than a Bitbucket-specific field. The REST API for pipeline steps does not include a property such as termination_signal or grace_period_seconds. Treat the exit-code mapping as a strong convention, not a guaranteed API contract, because runner internals can change without notice.
SIGTERM inside your own process. Because Bitbucket will not call a pre-stop script, your application or wrapper script must install its own signal handler. For example, a shell wrapper can trap 'cleanup' TERM before exec'ing the main process.SIGKILL deadline.timeout in the step definition so the runner initiates the same signal sequence deterministically, rather than relying on a human clicking cancel at an arbitrary moment.143 indicates the process received SIGTERM; 137 indicates it was killed by SIGKILL after the grace period expired.If your graceful shutdown routinely needs more than 10 seconds, in-process signal trapping will not be sufficient, and the correct pattern is to move cleanup out of the step entirely—for example, by writing a completion marker to durable storage and letting a separate worker finish the job. If cleanup is under 10 seconds, the steps above are enough. How long does your shutdown path typically take?
Version assumption: This reflects Bitbucket Cloud Pipelines behavior as documented through 2024. Self-hosted runner environments may offer different low-level controls; verify against your specific runner version before relying on undocumented internals.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.