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

オープン 初心者向け
#17,455 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

変更は comfy_api_nodes/apis/__init__.py と nodes.py を init_builtin_api_nodes() 内で行います。モデルのインポートとノードの読み込みを指定の通り gc.disable()/gc.enable() で囲みます。完了とは、ComfyUI が Windows で複数回の実行後にアクセス違反なく起動することを意味します。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Python
スター
146k
フォーク
17.4k
平均マージ
19時間 44分
マージ済み PR(30日)
178

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Comfy-Org/ComfyUI のほかの issue

Comfy-Org/ComfyUI の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。