Skip to content

[Bug]: Windows: _pin_hash_seed_if_needed re-exec returns before the command finishes, or segfaults #3799

Description

@ThatAblaze

What happened?

graphify extract / update / cluster-only / label re-exec themselves via os.execvpe to
pin PYTHONHASHSEED=0 (#3641, #3779) when the caller has not set it. On Windows os.exec* does
not replace the process: CPython starts a new process and the calling one exits. The caller
therefore sees the command finish immediately while the real work continues detached, and in
some runs the process crashes instead.

Steps to reproduce

Repro (Git Bash, any small corpus, `PYTHONHASHSEED` unset):

rm -rf graphify-out
env -u PYTHONHASHSEED python -m graphify extract . --code-only; echo "exit=$?"
ls graphify-out/graph.json


Observed over three runs:
- exit 0 after ~0.5 s, `graph.json` absent on return, appears a few seconds later (the detached
  child finished it);
- exit 139 (segmentation fault / access violation), no output (twice).

Error output or graph output

Effect: any script that runs `extract` and then reads `graph.json` (or runs `cluster-only`) fails
intermittently on Windows. Setting `PYTHONHASHSEED=0` before calling graphify avoids the re-exec
and everything works.

Suggested fix: on Windows (`os.name == "nt"`), run the child with
`subprocess.run([sys.executable, "-m", "graphify", *sys.argv[1:]], env=...)` and
`sys.exit(result.returncode)` instead of `os.execvpe`, so the parent waits and propagates the
exit status.

Graphify version

No response

Environment

graphify 0.9.67 (pip graphifyy), Python 3.13.1, Windows 10 (10.0.19045)

Additional context

No response

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions