You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: Caching of load_nvidia_dynamic_lib result implies "never close the handle". #1011
cuda.pathfinder.load_nvidia_dynamic_lib(libname) returns a LoadedDL whose OS handle (_handle_uint) must not be closed by callers. The function is decorated with functools.cache, so the same handle instance is shared across
the process. If user code calls dlclose (Linux) or FreeLibrary (Windows) on that handle, it can unload the module while other code still uses it, resulting in crashes or subtle failures.
This behavior is by design of the current caching, but it was not explicitly documented until now.
Affected platforms
Linux and Windows (these are the only supported platforms for this loader).
How it shows up
After calling load_nvidia_dynamic_lib(...), code looks up symbols via dlsym / GetProcAddress, then unloads the library.
Later, other code (or a subsequent call to load_nvidia_dynamic_lib) uses the cached handle and crashes or fails to resolve symbols.
Minimal example (illustrative)
fromcuda.pathfinderimportload_nvidia_dynamic_libloaded=load_nvidia_dynamic_lib("cudart")
handle=loaded._handle_uint# ❌ Do not do this – it can unload a cached, shared handle:# Linux: ctypes.CDLL("libdl.so").dlclose(ctypes.c_void_p(handle))# Windows: kernel32.FreeLibrary(ctypes.c_void_p(handle))# Later use of the cached handle may now fail or crash.
Activity
rwgk commentedon Mar 4, 2026
The behavior is clearly documented as of Sep 2025. We don't have any concrete plans to change this behavior at the moment. Closing for now.