fix(nixl): make FILE path-mode devId globally unique (#34362)

Co-authored-by: hekh <hekh@local>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
hekhong-png
2026-09-01 09:11:59 -07:00
committed by GitHub
co-authored by hekh Claude
parent bb3e3cbceb
commit c34f378342
@@ -51,6 +51,12 @@ class NixlRegistry:
# from a single monotonic counter. # from a single monotonic counter.
self._obj_devid_lock = threading.Lock() self._obj_devid_lock = threading.Lock()
self._obj_devid_next = 1 self._obj_devid_next = 1
# FILE path-mode devIds must also be globally unique: nixlBasicDesc
# matches by (devId, addr, len) and excludes metaInfo (the file path),
# so per-batch i+1 collides across concurrent batches and deregister
# can close the wrong fd (EBADF). Mirror the OBJ counter above.
self._file_devid_lock = threading.Lock()
self._file_devid_next = 1
self.path_mode = mem_type == "FILE" and self._probe_path_mode() self.path_mode = mem_type == "FILE" and self._probe_path_mode()
if mem_type == "FILE" and self.path_mode: if mem_type == "FILE" and self.path_mode:
logger.info("HiCacheNixl: path-mode FILE registration active.") logger.info("HiCacheNixl: path-mode FILE registration active.")
@@ -148,8 +154,12 @@ class NixlRegistry:
if self.file_manager.use_direct_io: if self.file_manager.use_direct_io:
parts.append("direct") parts.append("direct")
spec = ",".join(parts) spec = ",".join(parts)
n = len(keys)
with self._file_devid_lock:
base = self._file_devid_next
self._file_devid_next += n
tuples = [ tuples = [
(0, sizes[i], i + 1, f"{spec}:{keys[i]}") for i in range(len(keys)) (0, sizes[i], base + i, f"{spec}:{keys[i]}") for i in range(n)
] ]
with self._registered(tuples, "FILE") as reg: with self._registered(tuples, "FILE") as reg:
if reg is None: if reg is None: