mirror of
https://github.com/Comfy-Org/comfy-aimdo.git
synced 2026-11-04 23:37:21 +00:00
[PR #106] [MERGED] Refuse a second init_devices() before plat_init() #119
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-aimdo#119
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-aimdo/pull/106
Author: @PozzettiAndrea
Created: 9/5/2026
Status: ✅ Merged
Merged: 9/6/2026
Merged by: @rattus128
Base:
master← Head:pr/init-devices-guard📝 Commits (1)
77b5882Refuse a second init_devices() before plat_init()📊 Changes
2 files changed (+23 additions, -0 deletions)
View changed files
📝
comfy_aimdo/control.py(+4 -0)➕
tests/init-devices-twice-cuda.py(+19 -0)📄 Description
Calling
init_devices()twice crashes the process on the next allocation.The second call runs
plat_init()again. That installs a new set of CUDA hooks over the live ones, so the first set is orphaned.lib.init()then rejects the duplicate devices, and the failure path callsplat_cleanup(), which tears down the live hooks and zeroes the dispatch table. The next torch allocation lands in the orphaned hook and callscuCtxGetDevicethrough a NULL slot (src/control.c:102). Python sawinit_devices()return False and then died.Refuse the call while
devctxsis non-empty.deinit()first is the supported way to reinitialize, as before. Python only;plat_init()itself stays non-reentrant (aimdo_setup_hooksstacks a second hook set,xfer_file_initresets a live thread pool), which is a separate C change I can send next.Found while probing from comfy-env, which initializes aimdo per worker subprocess (memory_manager.py:261-268).
tests/init-devices-twice-cuda.py: exit 139 on 0.4.13, passes with this patch. RTX 3090, torch 2.8 cu128.Contribution Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.