Skip to content

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

Closed

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?

Activity

  1. thejcannon commented on Jun 4, 2026

    @thejcannon
    ContributorAuthor

    From grepping around this may also affect

    # We want to use os.execv instead of subprocess.call, which causes

  2. rickeylev commented on Jun 7, 2026

    @rickeylev
    Collaborator

    Yeah, this is a known issue. Properly forwarding the signals requires some subtle code.

    Happy to have a PR for this. An LLM can probably figure it out relatively well.

  3. jpneufeld commented on Sep 15, 2026

    @jpneufeld
    Contributor

    @rickeylev I hit this so I had an llm post a fix

  4. added a commit that references this issue on Oct 16, 2026
    29b0942
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions