Skip to content

update/cluster-only fail with os.replace WinError 5 on VMware HGFS shared folders (read-then-replace over existing graph.json) #2689

Closed

Description

@hounvs

graphify: 0.9.41
OS: Windows Server 2019, Python 3.14
Filesystem: repo on a VMware Shared Folders drive (\\vmware-host\Shared Folders, HGFS)

Summary

On a repo hosted on a VMware HGFS shared drive, graphify update . (and any command
that rewrites an existing graph.json, e.g. cluster-only, label) fails at the final
atomic write:

[graphify watch] Rebuild failed: [WinError 5] Access is denied: 'graphify-out\.graph.tmp.json' -> 'graphify-out\graph.json'

The graph is computed correctly (.graph.tmp.json is written); only the os.replace()
onto the existing graph.json fails. Because the run aborts there, GRAPH_REPORT.md,
graph.html, and manifest.json are never written. The un-advanced manifest means every
later run re-detects the same delta and fails at the same spot, so incremental updates are
permanently blocked on this filesystem.

Looks related to #287 (also os.replace WinError 5) but still reproduces on 0.9.41, so
that fix does not cover this path.

Root cause

On HGFS, os.replace(tmp, dst) raises PermissionError(13) when dst was read earlier
in the same process
before being replaced. graphify's incremental write reads the existing
graph.json (merge / shrink-guard), then os.replace()s the temp over it, which HGFS denies.
First-ever builds succeed because there is no existing graph.json to read.

Minimal reproduction (no graphify required)

On a VMware HGFS shared drive:

import os
open('dst.json', 'w').write('x' * 1_300_000)
_ = open('dst.json').read()            # read before replace (the trigger)
open('.tmp.json', 'w').write('y' * 1_500_000)
os.replace('.tmp.json', 'dst.json')    # PermissionError(13, 'Access is denied') on HGFS

Controls (same machine, same code):

  • Remove the intervening read() and os.replace succeeds on the same HGFS share.
  • os.remove('dst.json'); os.rename('.tmp.json', 'dst.json') (delete-then-rename) succeeds even with the read.
  • Run the exact snippet on a local NTFS path (C:\...) and it succeeds.

So it is specific to (read-then-replace) on HGFS, not a general Windows or handle-leak issue.

Suggested fix

Fall back to delete-then-rename when os.replace raises PermissionError / WinError 5:

try:
    os.replace(tmp, dst)
except PermissionError:
    os.remove(dst)
    os.rename(tmp, dst)

Delete-then-rename is non-atomic, so keep os.replace as primary and use this only as a fallback.

Activity

  1. safishamsi commented on Sep 15, 2026

    @safishamsi
    Member

    Fixed in v0.9.62 (on PyPI) via #3555, thanks @ayushcodes10. Thanks for the report!

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