Fix: Windows access violation during startup when loading comfy_api_nodes (pydantic-core GC issue)

Open Beginner friendly
#17,455 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

The changes go in comfy_api_nodes/apis/__init__.py and nodes.py inside init_builtin_api_nodes(). Wrap the model imports and node loading with gc.disable()/gc.enable() as specified. Done means ComfyUI starts on Windows without the access violation after multiple runs.

Written by the indexing model from the issue text.

Description

Problem

On Windows, ComfyUI crashes at startup with Windows fatal exception: access violation while loading the built-in API nodes (comfy_api_nodes). The stack trace points to pydantic's schema generation, triggered during import of comfy_api_nodes/apis/__init__.py (a file with ~1000+ pydantic models).

Root cause

This is a known bug in pydantic-core on Windows: the cyclic garbage collector traverses pydantic-core's internal objects (validators/serializers) while they are still being constructed, corrupting refcounts and causing the access violation. Tracked in pydantic discussion #13839.

Fix

Disable the cyclic GC while constructing all pydantic models in apis/__init__.py and during the loading of built-in API nodes:

In comfy_api_nodes/apis/__init__.py (add at the top):
import gc as _gc
_gc_was_enabled = _gc.isenabled()
_gc.disable()

And at the very end of the file:

if _gc_was_enabled:
    _gc.enable()
In nodes.py -> init_builtin_api_nodes():
import gc
gc_was_enabled = gc.isenabled()
gc.disable()
try:
    for node_file in api_nodes_files:
        if not await load_custom_node(node_file, module_parent="comfy_api_nodes"):
            import_failed.append(os.path.basename(node_file))
finally:
    if gc_was_enabled:
        gc.enable()

Verification

Tested across 8 consecutive startup runs — all completed successfully with no access violations.

Environment

  • Windows 11, Python 3.12.10
  • pydantic 2.14.2, pydantic-core 2.50.2
  • ComfyUI 0.42.5
Dominant language
Python
Stars
146k
Forks
17.4k
Avg merge
19h 44m
Merged PRs (30d)
178

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Comfy-Org/ComfyUI

All issues in Comfy-Org/ComfyUI

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.