Skip to content

Segfault on macOS when setproctitle() is called after os.fork() in worker processes #446

@tobikugel

Description

@tobikugel

Hello 👋
I spent several hours trying to get this library running on macOS (arm64) with Python 3.12. Eventually I discovered that mutmut consistently crashes with a SIGSEGV (exit code -11) in its worker processes before any tests actually run.

The crash disappears if I comment out this line:
main.py L1091

setproctitle(f"mutmut: {mutant_name}")

This call is executed in the child process immediately after os.fork().
Removing or guarding it makes mutation testing work normally.

What happens

Running mutmut run causes every worker to exit with code -11 unless I comment out the setproctitle(...) call in the child branch.

When pytest is invoked inside the worker, Python reports a fatal segmentation fault:

    worker exit code -11

Running a single mutant with pytest output enabled also shows “Segmentation fault” before any test code executes.
Once I disable setproctitle(...), workers proceed and mutation testing completes successfully.

Expected behavior

Workers should start and run tests normally.
setproctitle(...) should not cause a crash in the child process.

Actual behavior

Calling setproctitle(...) in the child immediately after a raw os.fork() reliably segfaults on macOS arm64.

Analysis

This is what my LLM said: This appears to be a classic “fork-without-exec” issue with native extensions on macOS.
After fork(), only async-signal-safe operations are guaranteed to be safe in a multi-threaded process.
Calling into a C extension (such as setproctitle) right after fork is known to be fragile on macOS; similar crashes are seen in other projects that call non-fork-safe C code immediately after forking.

setproctitle(...) is the first native call made by the child.
Removing it completely avoids the crash and mutation testing proceeds normally.

Environment

  • OS: macOS 14 + (Darwin arm64) — platform: macOS-26.0.1-arm64-arm-64bit
  • Python: 3.12.11 (venv)
  • mutmut: 3.3.1
  • pytest: 8.4.2
  • setproctitle: 1.3.7

Reproduction steps

  1. On macOS arm64 with Python 3.12, install mutmut and setproctitle.
  2. Run mutmut run on any project.
  3. Observe that worker processes exit with -11.
  4. Comment out or guard the line
    setproctitle(f"mutmut: {mutant_name}")
    and re-run — the crash disappears.

I can submit a PR implementing a platform-safe guard around setproctitle(...) (e.g. skip on macOS).
Let me know if I can help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions