Skip to content

(Linux) The stage-1 bootstrap script does not propagate certain signals to the stage-2 bootstrap script.  #2043

@chowder

Description

@chowder

🐞 bug report

Affected Rule

The issue is caused by the rule: py_binary / py_test

Is this a regression?

Yes.

Description

(This bug report is specific to Linux)

In the old 1-stage bootstrap script, the script eventually runs the underlying program with os.execv, which replaces the process entirely, so that's ok - any signals get propagated directly to our program.

def _RunExecv(python_program, main_filename, args, env):
  # type: (str, str, list[str], dict[str, str]) -> ...
  """Executes the given Python file using the various environment settings."""
  os.environ.update(env)
  PrintVerbose("RunExecv: environ:", os.environ)
  argv = [python_program, main_filename] + args
  PrintVerbose("RunExecv: argv:", python_program, argv)
  os.execv(python_program, argv)

https://github.com/bazelbuild/rules_python/blob/main/python/private/python_bootstrap_template.txt#L379-L386

In the new 2-stage boostrap script(s), the first stage invokes the second stage directly:

env \
  "${interpreter_env[@]}" \
  "$python_exe" \
  "${interpreter_args[@]}" \
  "$stage2_bootstrap" \
  "$@"

exit $?

https://github.com/bazelbuild/rules_python/blob/main/python/private/stage1_bootstrap_template.sh#L111-L116

I'm not sure if it's platform depedent - but at least on Debian and CentOS, bash will start a child process, and signals like SIGINT don't get handled nor propagated.

I think this is a simple fix, changing the stage-2 invocation to:

exec env \
  "${interpreter_env[@]}" \
  "$python_exe" \
  "${interpreter_args[@]}" \
  "$stage2_bootstrap" \
  "$@"

I'm happy to raise a PR for the above if it is agreed to be OK.

🔬 Minimal Reproduction

I don't have one at hand, but I can provide one if needed.

🌍 Your Environment

Operating System:

Linux AMD64 - CentOS 7, and Debian 11

Output of bazel version:

Bazel 7.2.1

Rules_python version:

0.34.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions