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

Đang mở Phù hợp với người mới
#17,455 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Các thay đổi nằm trong comfy_api_nodes/apis/__init__.py và nodes.py bên trong init_builtin_api_nodes(). Bọc các import mô hình và việc tải node bằng gc.disable()/gc.enable() như được chỉ định. Xong nghĩa là ComfyUI khởi động trên Windows mà không gặp vi phạm truy cập sau nhiều lần chạy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
146k
Fork
17.4k
Merge trung bình
19 giờ 44 phút
Pull request đã merge (30 ngày)
178

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Comfy-Org/ComfyUI

Tất cả issue của Comfy-Org/ComfyUI

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.