Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scriptworker_client: properly handle signals in run_command #1030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions scriptworker_client/src/scriptworker_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import random
import shutil
import signal
import tempfile
from asyncio.subprocess import PIPE
from contextlib import contextmanager
Expand Down Expand Up @@ -174,9 +175,7 @@ async def run_command(
env=None,
exception=None,
expected_exit_codes=(0,),
# https://stackoverflow.com/questions/18731791/determining-if-a-python-subprocess-segmentation-faults
# Shell exit codes range from 0 to 255. Therefore 245 == -11, 241 == -15
copy_exit_codes=(245, 241),
copy_exit_codes=(-signal.SIGTERM, -signal.SIGSEGV),
output_log_on_exception=False,
):
"""Run a command using ``asyncio.create_subprocess_exec``.
Expand Down Expand Up @@ -209,7 +208,7 @@ async def run_command(
Defaults to ``(0, )``.
copy_exit_codes (list, optional): the list of exit codes that we
set ``exit_code`` to if ``exception`` is an instance of
``ClientError``. Defaults to ``(245, 241)``.
``ClientError``. Defaults to ``(-15, -11)``.
output_log_on_exception (bool, optional): log the output log if we're
raising an exception.

Expand Down
4 changes: 2 additions & 2 deletions scriptworker_client/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def test_get_log_filehandle(path, tmpdir):
True,
),
(
["bash", "-c", ">&2 echo bar && echo foo && exit -11"],
245,
["bash", "-c", ">&2 echo bar && echo foo && kill -11 $$"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly this test was wrong originally. #324 also cites some real world testing, which might be good to do if you haven't already.

-11,
["foo\nbar\n", "bar\nfoo\n"],
TaskError,
True,
Expand Down