Comfy-Org / Comfy-Org/ComfyUI

regression: comfy-angle package breaks libffi functionality such as fish-speech - ffi_prep_closure() - loading libGLESv2.so globally (preload_angle() in nodes_glsl.py) poisons CFFI/libffi ?

Open
#15,134 2 comments 1 reaction 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 10h
Merged PRs (30d)
153

Description

Prefixing this with what I'm advised is more succinct than my wittering!

**In ComfyUI v0.28, `comfy_extras/nodes_glsl.py` imports `comfy_angle` and calls` ctypes.CDLL`(`libGLESv2.so`, `RTLD_GLOBAL`) at module import time. This causes `cffi` callbacks in `soundfile` to fail with `ffi_prep_closure(): bad user_data`. Removing the GLESv2 preload fixes the issue.**

### Expected Behavior

nodes using cffi callabacks like FishAudioS2 generation (e.g. https://github.com/Saganaki22/ComfyUI-FishAudioS2 ) should work, as they did on v 0.26

### Actual Behavior

Be example, FishAudioS2 generation, such as with https://github.com/Saganaki22/ComfyUI-FishAudioS2 errors "

`ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time)"
`

`uv run python -m pip uninstall comfy-angle`
fixes

### Steps to Reproduce

Run a workflow using above custom node.

I know, it's a custom node, but impacts soundfile handling so will presumably have wider impact

✅ FishAudioS2 is not the cause.
✅ soundfile, cffi, and libffi are not independently broken.
❌ The regression was introduced by ComfyUI 0.28's new nodes_glsl.py.
✅ The problematic action happens during import/startup, before FishAudio runs.

As a test, the problem is resolved by editing out # `_preload_angle()` in `comfy_extras/nodes_glsl.py`

more specifically, editing out ctypes.CDLL(str(gles_path), mode=mode) fixes it.

regressions seems to be caused by loading `libGLESv2.so` globally

### Debug Logs

```powershell
Comparing the two folders, I was expecting to see a difference in cffi, soundfile, torch, numpy, transformers or suchlike.
None.

a diff of python -m pip freeze between versions gives

in 0.28 i ran
uv run python -m pip freeze > broken.txt

then
diff working.txt broken.txt

output:
42,50c42,53
< comfy-kitchen==0.2.10
< comfyui-embedded-docs==0.5.5
< comfyui-workflow-templates-core==0.3.263
< comfyui-workflow-templates-media-api==0.3.81
< comfyui-workflow-templates-media-image==0.3.157
< comfyui-workflow-templates-media-other==0.3.226
< comfyui-workflow-templates-media-video==0.3.98
< comfyui_frontend_package==1.45.19
< comfyui_workflow_templates==0.10.7
---
> comfy-angle==0.1.0
> comfy-kitchen==0.2.20
> comfyui-embedded-docs==0.5.8
> comfyui-workflow-templates-core==0.3.275
> comfyui-workflow-templates-json==0.1.9
> comfyui-workflow-templates-media-api==0.3.84
> comfyui-workflow-templates-media-assets-01==0.1.5
> comfyui-workflow-templates-media-image==0.3.160
> comfyui-workflow-templates-media-other==0.3.229
> comfyui-workflow-templates-media-video==0.3.101
> comfyui_frontend_package==1.45.21
> comfyui_workflow_templates==0.11.12

the full error is as follows:

[INFO] got prompt
[FishAudioS2] Loading Fish S2 LLaMA from: /home/username/ComfyUI/models/fishaudioS2/s2-pro
[FishAudioS2] Device: cuda, Precision: torch.bfloat16
[FishAudioS2] Attention class patched with: sage_attention
[INFO] Loaded Tokenizer. Semantic Range: 151678 -> 155773
HunyuanVideo-Foley: Loading model from /home/username/ComfyUI/models/fishaudioS2/s2-pro
HunyuanVideo-Foley: Model memory estimate: 10.21 GB, Free VRAM: 26.02 GB
HunyuanVideo-Foley: Restored model from checkpoint
HunyuanVideo-Foley: Using DualARTransformer
[FishAudioS2] Attention class restored to default.
[FishAudioS2] Loading Fish S2 decoder from: /home/username/ComfyUI/models/fishaudioS2/s2-pro/codec.pth
HunyuanVideo-Foley: Loaded model: _IncompatibleKeys(missing_keys=[], unexpected_keys=['encoder.block.4.block.5.freqs_cis', 'encoder.block.4.block.5.causal_mask', 'quantizer.pre_module.freqs_cis', 'quantizer.pre_module.causal_mask', 'quantizer.post_module.freqs_cis', 'quantizer.post_module.causal_mask'])
[FishAudioS2] Fish S2 engine ready (attention=sage_attention).
[FishAudioS2] Encoding reference audio...
[ERROR] !!! Exception during processing !!! ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time)
[ERROR] Traceback (most recent call last):
File "/home/username/ComfyUI/execution.py", line 543, in execute
output_data, output_ui, has_subgraph, has_pending_tasks = await get_output_data(prompt_id, unique_id, obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/execution.py", line 342, in get_output_data
return_values = await _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/execution.py", line 316, in _async_map_node_over_list
await process_inputs(input_dict, i)
File "/home/username/ComfyUI/execution.py", line 304, in process_inputs
result = f(**inputs)
^^^^^^^^^^^
File "/home/username/ComfyUI/custom_nodes/ComfyUI-FishAudioS2/nodes/voice_clone_node.py", line 183, in generate
ref_bytes = audio_bytes_from_comfy(reference_audio)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/custom_nodes/ComfyUI-FishAudioS2/nodes/loader.py", line 650, in audio_bytes_from_comfy
sf.write(buf, wav, sample_rate, format="WAV", subtype="PCM_16")
File "/home/username/ComfyUI/.venv/lib/python3.12/site-packages/soundfile.py", line 363, in write
with SoundFile(file, 'w', samplerate, channels,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/.venv/lib/python3.12/site-packages/soundfile.py", line 690, in __init__
self._file = self._open(file, mode_int, closefd)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/.venv/lib/python3.12/site-packages/soundfile.py", line 1258, in _open
file_ptr = _snd.sf_open_virtual(self._init_virtual_io(file),
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/username/ComfyUI/.venv/lib/python3.12/site-packages/soundfile.py", line 1277, in _init_virtual_io
@_ffi.callback("sf_vio_get_filelen")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time)
```

### Other

I've mentioned this to custom node author, https://github.com/Saganaki22/ComfyUI-FishAudioS2/issues/48 however resolving the regression caused by comfy-angle would be better, as that would fix things for all processes and custom nodes which would be impacted by the change?

Contributor guide

Open the contributing guide

Research direction

Start in comfy_extras/nodes_glsl.py, especially the import-time _preload_angle() call and its ctypes.CDLL(str(gles_path), mode=mode) line. Reproduce the issue with the FishAudioS2 workflow and inspect how loading libGLESv2.so globally affects the soundfile CFFI callback. Done means the GLSL functionality remains usable while the workflow no longer raises the ffi_prep_closure() error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.