Skip to content

Fix: Remove aggressive sys.modules cleanup causing ComfyUI segfault#217

Open
ChrisFab16 wants to merge 1 commit intoGourieff:mainfrom
ChrisFab16:fix-comfyui-sysmodules-crash
Open

Fix: Remove aggressive sys.modules cleanup causing ComfyUI segfault#217
ChrisFab16 wants to merge 1 commit intoGourieff:mainfrom
ChrisFab16:fix-comfyui-sysmodules-crash

Conversation

@ChrisFab16
Copy link

Fix: Remove aggressive sys.modules cleanup causing ComfyUI segfault

Issue

ComfyUI crashes with a segmentation fault during startup after loading custom nodes.

Root Cause Analysis

Comparing PR #194 changes, the diff shows the cleanup code was added:

# Added in PR #194:
modules_to_remove = []
for module in sys.modules:
    if module not in original_modules and not module.startswith("google.protobuf") and not module.startswith("onnx") and not module.startswith("cv2"):
        modules_to_remove.append(module)
for module in modules_to_remove:
    del sys.modules[module]

This cleanup removes modules from sys.modules that other custom nodes (loaded after ReActor) depend on, causing segmentation faults.

Solution

Removing this cleanup resolves the crash:

# In __init__.py, removed:
# - original_modules = sys.modules.copy()
# - The modules_to_remove loop
# Kept:
# - sys.path.remove(repo_dir)
# - sys.modules.update(original_webui_modules)

Additional Change

Unpinned versions for flexibility:

  • insightface>=0.7.3
  • numpy>=1.26.4

Question

The cleanup appears designed for a1111 webui compatibility. Would it make sense to add a check to only run cleanup when running in an a1111 context?

The cleanup code added in PR Gourieff#194 removes modules from sys.modules
that other custom nodes depend on, causing segmentation faults.

This fix removes the aggressive module cleanup while keeping
path cleanup and a1111 webui module restoration.

Also unpins versions for flexibility:
- insightface>=0.7.3
- numpy>=1.26.4
@Gourieff
Copy link
Owner

Yeah, thanks for PR my friend, I know about this issue, answered here #194 (comment)

About NSFW, if we add a possibility to disable NSFW filter, ReActor repo can be blocked again as it was in Jan 2025

@ChrisFab16 ChrisFab16 force-pushed the fix-comfyui-sysmodules-crash branch from a1f4213 to 3f9c7a5 Compare February 12, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants