Skip to content

Signal Handling

Ductwork responds to the TTIN signal by dumping backtraces for all child threads in the process. This is handy for figuring out what a hung or stalled process is doing in production.

When you send a TTIN signal to a Ductwork process, it prints the full call stack for each running thread. Each backtrace is prefixed with the thread’s name in the format ductwork.<role>_<id>, so you can tell which worker or advancer is doing what.

Usage:

Terminal window
# Find the Ductwork process ID
ps aux | grep ductwork
# Send the TTIN signal
kill -TTIN <pid>

The output prints directly to STDOUT instead of the configured logger.

Example Output:

ductwork.job_worker_3
/app/lib/some_operation.rb:42:in `process_data'
/app/steps/my_step.rb:15:in `perform'
...
ductwork.pipeline_advancer_1
/gems/ductwork/lib/pipeline_advancer.rb:28:in `advance'
...

Ductwork handles INT (Interrupt) and TERM (Terminate) signals the same way. Both start a graceful shutdown across all processes, which gives in-flight jobs a chance to finish before the process exits.

When the supervisor receives an INT or TERM signal, it shuts things down in this order:

  1. Signal Forwarding - The supervisor forwards the signal to all child processes, both the pipeline advancer and the job workers.

  2. Job Worker Shutdown - Job workers attempt a graceful shutdown by waiting for all active threads to complete their current work and join the parent process. Each thread has up to job_worker.shutdown_timeout seconds (default: 20) to finish. Once the timeout expires, any remaining threads are killed immediately to prevent hanging.

  3. Pipeline Advancer Shutdown - The pipeline advancer attempts a graceful shutdown by waiting for all active threads to complete their current work and join the parent process. Each thread has up to pipeline_advancer.shutdown_timeout seconds (default: 20) to finish. Once the timeout expires, any remaining threads are killed immediately to prevent hanging.

  4. Supervisor Shutdown - The supervisor waits for all child processes to exit cleanly, respecting the supervisor.shutdown_timeout value (default: 30 seconds). If any processes are still alive after the timeout, they receive a SIGKILL and terminate immediately.

INT/TERM received
↓
Supervisor forwards signal to children
↓
Job workers wait for threads (up to job_worker.shutdown_timeout)
├─ Threads finish gracefully ✓
└─ Or are killed after timeout ✗
Pipeline advancer waits for threads (up to pipeline_advancer.shutdown_timeout)
├─ Threads finish gracefully ✓
└─ Or are killed after timeout ✗
↓
Supervisor waits for children (up to supervisor.shutdown_timeout)
├─ Children exit gracefully ✓
└─ Or are killed after timeout ✗
↓
Supervisor exits
  • Set appropriate timeouts: Ensure supervisor.shutdown_timeout is larger than job_worker.shutdown_timeout to allow proper cascading.
  • Keep jobs short: Design step jobs to complete quickly so they can finish within the shutdown window.
  • Monitor shutdown: Use lifecycle hooks like on_worker_stop and on_supervisor_stop to track shutdown behavior and timing.
Terminal window
# Graceful shutdown with INT
kill -INT <pid>
# Or with TERM
kill -TERM <pid>

A graceful shutdown keeps data consistent and avoids orphaned work, so you can deploy updates or scale down your Ductwork processes without losing in-progress pipeline work.