# 运行时错误：NCCL 错误：套接字错误：连接到 192.168.1.100:29500 失败：连接超时

- **ID:** `cuda/nccl-socket-timeout-connect`
- **领域:** cuda
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

NCCL 无法在分布式训练设置中与对等节点建立 TCP 连接，通常是由于防火墙规则、IP 地址错误或网络接口配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| NCCL 2.18.5 | active | — | — |
| NCCL 2.19.3 | active | — | — |
| CUDA 12.2 | active | — | — |
| PyTorch 2.1 | active | — | — |

## 解决方案

1. ```
   使用命令 nc -zv 192.168.1.100 29500 从每个节点验证网络连通性。如果失败，请在防火墙中打开该端口（默认 29500），或使用 NCCL_SOCKET_IFNAME 和 NCCL_IB_DISABLE=1 指定不同的端口。
   ```
2. ```
   设置 NCCL_SOCKET_IFNAME=eth0（或正确的网络接口），强制 NCCL 使用特定接口。同时确保所有节点可以通过该接口相互访问。
   ```
3. ```
   禁用 InfiniBand 并仅使用 TCP：export NCCL_IB_DISABLE=1。如果 IB 配置错误但 TCP 正常工作，此方法很有用。
   ```

## 无效尝试

- **** — A timeout increase only delays failure; if the connection cannot be established, it will eventually time out regardless, wasting resources. (90% 失败率)
- **** — The issue is network-related, not installation-related. Reinstalling doesn't change firewall rules or IP configurations. (95% 失败率)
- **** — Socket connection logic is similar across versions; downgrading may introduce other bugs without fixing the connectivity problem. (85% 失败率)
