DEBUG.WIKI
RackNerd;$21.99/年 · 1GB KVM
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →
腾讯云;让你的想法跑起来;轻量服务器 · 建站 / Docker / API;查看产品 →

解决 Jenkins 报错 ChannelClosedException 节点离线修复

排查 Jenkins 自动化流水线构建中断提示 hudson.remoting.ChannelClosedException: Channel ... is already closed,排查 Agent 节点 OOM 与心跳保活。

问题现象

Jenkins Pipeline 正在执行漫长打包时,任务突发中断并红牌失败:

FATAL: hudson.remoting.ChannelClosedException: 
Channel "hudson.remoting.Channel@1a2b3c:JNLP4-connect connection to build-agent-1": 
Remote call on build-agent-1 failed. The channel is closing down or has closed down
Caused by: java.io.IOException: Unexpected termination of the channel

触发根因

  1. 构建 Agent 节点因为内存超限被 Linux 内核 OOM-Killer 强行杀死:Agent 执行构建时子进程吃满物理内存,Linux 内核杀死 remoting.jar 进程导致 TCP 会话瞬间被 RST 关闭;
  2. Master 与 Agent 之间的网络超时(JNLP PING 超时);
  3. Kubernetes 动态挂载的 Agent Pod 达到 CPU/Memory Limit 被直接驱逐。

解决步骤

1. 在 Agent 宿主机查看内核 dmesg 确认 OOM 事件

在终端执行检查:

dmesg -T | grep -i oom-killer

若看到 Out of memory: Kill process (java) score ...,说明确实因内存耗尽被杀。

2. 在 Jenkins 控制台放宽 JNLP 网络心跳超时阈值

在 Jenkins 启动参数追加:

-Dhudson.remoting.Launcher.pingIntervalSec=30
-Dhudson.remoting.Launcher.pingTimeoutSec=120

3. 为 Agent 容器分配更高的物理内存上限

在 Kubernetes Pod Template 中为 Agent 容器分配合理资源配额:

resources:
  requests:
    memory: "2Gi"
  limits:
    memory: "8Gi"

验证确认

重新触发大工程并发构建:

Agent 节点长连接保持完好,任务全程执行完毕,状态显示蓝色 SUCCESS。