{"record":{"id":"e3ca8f5e6619eb78","repo":"sgl-project/sglang","slug":"duplicate-fd-for-key","errorCode":null,"errorMessage":"duplicate fd for {key}","messagePattern":"duplicate fd for (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/cuda_vmm_utils.py","lineNumber":810,"sourceCode":"    server.settimeout(_FD_SEND_TIMEOUT_S)\n    received_fds = {}\n    errors = []\n\n    def recv_loop():\n        try:\n            for _ in range(world_size - 1):\n                conn, _ = server.accept()\n                with conn:\n                    conn.settimeout(_FD_SEND_TIMEOUT_S)\n                    while True:\n                        packet = _recv_fd(conn)\n                        if packet is None:\n                            break\n                        src_rank, base_idx, fd = packet\n                        key = (src_rank, base_idx)\n                        if key in received_fds:\n                            os.close(fd)\n                            raise RuntimeError(f\"duplicate fd for {key}\")\n                        received_fds[key] = fd\n        except BaseException as e:\n            errors.append(e)\n\n    try:\n        server.bind(sock_path)\n        server.listen(world_size)\n        paths = [None] * world_size\n        dist.all_gather_object(paths, sock_path, group=group)\n\n        thread = threading.Thread(target=recv_loop, daemon=True)\n        thread.start()\n        try:\n            for peer_rank, peer_path in enumerate(paths):\n                if peer_rank == rank:\n                    continue\n                with socket.socket(socket.AF_UNIX, sock_kind) as sock:\n                    sock.settimeout(_FD_SEND_TIMEOUT_S)","sourceCodeStart":792,"sourceCodeEnd":828,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/cuda_vmm_utils.py#L792-L828","documentation":"During the POSIX fd exchange receive loop, a duplicate (src_rank, base_idx) key means the same peer segment was delivered twice. The fd is closed and an error raised to avoid double-mapping or leaking a handle, indicating a misbehaving sender or protocol violation.","triggerScenarios":"recv_loop receives two packets with the same (src_rank, base_idx) pair — a peer rank sending its fd list twice, or multiple senders claiming the same rank id.","commonSituations":"Ranks restarted mid-exchange resending fds, rank-id collision due to misconfigured distributed env (MASTER_ADDR/RANK/WORLD_SIZE mismatch), or duplicate sockets connecting to the exchange server.","solutions":["Verify distributed env config (RANK, WORLD_SIZE, MASTER_ADDR) is consistent across ranks.","Check for rank restart/retry logic that re-runs exchange_posix_fds against a live receiver.","Rerun the job from a clean start if ranks were partially restarted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert len({(r, b) for r, b, _ in packets}) == len(packets), \"duplicate (rank, base_idx) before install\"","typeGuard":null,"tryCatchPattern":"try:\n    received = exchange_posix_fds(...)\nexcept RuntimeError as e:\n    if \"duplicate fd\" in str(e):\n        raise RuntimeError(\"rank restart/protocol violation — rerun job cleanly\") from e\n    raise","preventionTips":["Ensure ranks start exactly once per exchange","Validate RANK/WORLD_SIZE consistency across the job"],"tags":["distributed","fd-passing","duplicate-key","protocol"],"backgroundTag":"duplicate-message-received","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}