Skip to content

macOS : test_setproctitle_crashes_after_fork_with_corefoundation_loaded fails in about half of the runs #622

Done

Description

@zyv

On my Mac, test_setproctitle_crashes_after_fork_with_corefoundation_loaded fails in about half of the test suite runs with "setproctitle did NOT crash (exit code 0)", also on main without any changes. CI runs on Ubuntu only, so it never sees this test. I noticed this while trying to come up with PRs for mutmut (#621) and this non-determinism makes it quite annoying.

According to my understanding, the test is the canary for the workaround from #446 and #450. I haven't found any already reported issues regarding the non-determinism, though.


The crash that the test asserts is not deterministic: when a forked child calls setproctitle after the parent did, the child segfaults in about half of the runs and exits cleanly in the rest. I don't know why it's random: the parent is already multithreaded before every fork (pthread_is_threaded_np()), and sleeping before the fork doesn't change the rate.

Forking several children and asserting that at least one of them crashes doesn't work either: my first try hung, with a child blocked in _LSSetApplicationInformationItem, waiting for a reply from LaunchServices.


So maybe instead of trying to fix the test, it's worth removing it altogether and only keeping test_safe_setproctitle_does_not_crash_after_fork, which tests the workaround itself.

Shall I submit a PR or do you want to keep/fix the test?

Reproducer

macOS 27.0.1, Python 3.15.0, setproctitle 1.3.8, repro.py:

import os

from setproctitle import setproctitle

setproctitle("parent process")
pid = os.fork()
if pid == 0:
    setproctitle("child process")
    os._exit(0)
_, status = os.waitpid(pid, 0)
print(f"signal {os.WTERMSIG(status)}" if os.WIFSIGNALED(status) else f"exit {os.WEXITSTATUS(status)}")
for i in $(seq 100); do python repro.py 2>/dev/null; done | sort | uniq -c
  51 exit 0
  49 signal 11

Activity

  1. zyv commented on Dec 1, 2026

    @zyv
    ContributorAuthor

    Alright, I've prepared a PR removing the flaky canary, because after further research I'm confident that it cannot be made deterministic, and trying to get it to 99% or so by using multiple trials just isn't worth it - it should rather be a documented platform limitation with a positive test and left at that in my opinion.

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