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:
# Find the Ductwork process IDps aux | grep ductwork
# Send the TTIN signalkill -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' ...INT and TERM
Section titled “INT and TERM”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.
How It Works
Section titled “How It Works”When the supervisor receives an INT or TERM signal, it shuts things down in this order:
-
Signal Forwarding - The supervisor forwards the signal to all child processes, both the pipeline advancer and the job workers.
-
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_timeoutseconds (default: 20) to finish. Once the timeout expires, any remaining threads are killed immediately to prevent hanging. -
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_timeoutseconds (default: 20) to finish. Once the timeout expires, any remaining threads are killed immediately to prevent hanging. -
Supervisor Shutdown - The supervisor waits for all child processes to exit cleanly, respecting the
supervisor.shutdown_timeoutvalue (default: 30 seconds). If any processes are still alive after the timeout, they receive aSIGKILLand terminate immediately.
Shutdown Sequence
Section titled “Shutdown Sequence”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 exitsBest Practices
Section titled “Best Practices”- Set appropriate timeouts: Ensure
supervisor.shutdown_timeoutis larger thanjob_worker.shutdown_timeoutto 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_stopandon_supervisor_stopto track shutdown behavior and timing.
# Graceful shutdown with INTkill -INT <pid>
# Or with TERMkill -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.