Skip to content

Zipapp doesn't forward signals (SIGTERM and friends) to the process, resulting in orphaned processes and no cleanup #3809

@thejcannon

Description

@thejcannon

🐞 bug report

Affected Rule

The issue is caused by the rule: `py_binary`

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Unsure

Description

A clear and concise description of the problem...

When running a py_binary zipapp (E.g. bazel build --build_python_zip <tgt>) signals such as SIGTERM aren't forwarded to the binary itself, meaning the process doesn't get a chance to clean up.

I suspect

ret_code = subprocess.call(subprocess_argv, env=env, cwd=workspace)
print_verbose("subprocess exit code:", ret_code)
sys.exit(ret_code)
is the source of the issue

🔬 Minimal Reproduction

Given

import signal

signal.signal(signal.SIGTERM, lambda _1, _2: print("SIGTERM"))

while True:
    pass

Then bazel run <tgt> and a kill -s TERM <pid> will print SIGTERM. But bazel build --build_python_zip <tgt> followed by a python <tgt>.zip and a kill -s TERM <pid> (of the outer process) results in the process being terminated and the underlying process being orphaned 💔

🔥 Exception or Error

N/A

🌍 Your Environment

Operating System:

  
x64 Ubuntu
  

Output of bazel version:

  
Build label: 8.6.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Feb 26 19:55:20 2026 (1772135720)
Build timestamp: 1772135720
Build timestamp as int: 1772135720
  

Rules_python version:

  
1.9.0
  

Anything else relevant?

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