Skip to content

Commit

Permalink
global: fix graceful shutdown
Browse files Browse the repository at this point in the history
When using the shell form of `CMD`, the provided command is executed
using `/bin/sh -c`, which breaks signal propagation. Use `exec` to
substitute the `sh` process and fix handling of signals by uwsgi.

Also handle SIGTERM in `consume-job-queue` to gracefully stop consuming
the job status queue.

Closes reanahub/reana-job-controller#347
  • Loading branch information
mdonadoni committed Sep 21, 2023
1 parent d48ef46 commit a2c5baa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Version 0.9.1 (UNRELEASED)
- Changes uWSGI configuration to increase buffer size, add vacuum option, etc.
- Fixes job status inconsistency by correctly setting running jobs' status to ``stopped`` when a workflow is stopped.
- Fixes uWSGI memory consumption on systems with very high allowed number of open files.
- Fixes uWSGI and ``consume-job-queue`` command to gracefully stop when being terminated.

Version 0.9.0 (2023-01-19)
--------------------------
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ ENV FLASK_APP=reana_workflow_controller/app.py \
EXPOSE 5000

# Run server
# exec is used to make sure signals are propagated to uwsgi,
# while also allowing shell expansion
# hadolint ignore=DL3025
CMD uwsgi \
CMD exec uwsgi \
--buffer-size ${UWSGI_BUFFER_SIZE} \
--die-on-term \
--hook-master-start "unix_signal:2 gracefully_kill_them_all" \
--hook-master-start "unix_signal:15 gracefully_kill_them_all" \
--enable-threads \
--http-socket 0.0.0.0:5000 \
--master \
Expand Down
9 changes: 9 additions & 0 deletions reana_workflow_controller/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""REANA Workflow Controller command line interface."""

import logging
import signal

Check warning on line 12 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L12

Added line #L12 was not covered by tests

import click
from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL
Expand All @@ -21,4 +22,12 @@ def consume_job_queue():
"""Consumes job queue and updates job status."""
logging.basicConfig(level=REANA_LOG_LEVEL, format=REANA_LOG_FORMAT)
consumer = JobStatusConsumer()

def stop_consumer(signum, frame):
logging.info("Stopping job status consumer...")
consumer.should_stop = True

Check warning on line 28 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L26-L28

Added lines #L26 - L28 were not covered by tests

signal.signal(signal.SIGTERM, stop_consumer)

Check warning on line 30 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L30

Added line #L30 was not covered by tests

logging.info("Starting job status consumer...")

Check warning on line 32 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L32

Added line #L32 was not covered by tests
consumer.run()

0 comments on commit a2c5baa

Please sign in to comment.