DEBUG.WIKI
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证

解决 Jenkins 报错 ChannelClosedException: Channel was closed 节点掉线修复

排查 Jenkins 运行构建时 Agent 突发断连报 hudson.remoting.ChannelClosedException: Channel was closed,分析 OOM 崩溃与网络抖动。

问题现象

长时间编译构建时,Console Output 突然中断:

FATAL: command execution failed
hudson.remoting.ChannelClosedException: Channel "unknown": Remote call on JNLP4-connect connection from 10.0.1.50 failed. The channel is closing down or has closed
Caused by: java.io.IOException: Unexpected termination of the channel

触发根因

  1. Agent 节点物理内存耗尽,系统内核 OOM Killer 杀掉了 remoting.jar 进程;
  2. Master 与 Agent 之间的网络跨专线出现 TCP 丢包或 NAT 会话超时关闭;
  3. 宿主机或虚拟机突然发生断电、重启或被云平台抢占回收。

解决步骤

检查 Agent 机器系统日志确认是否触发 OOM

查看系统日志:

sudo dmesg -T | grep -i oom

若是 OOM,调大 Agent 节点物理内存并为编译任务限制并发线程数。

优化 remoting.jar 启动参数与心跳机制

在 Agent 启动脚本中加入保活与内存保护:

java -Xms512m -Xmx2048m -Dorg.jenkinsci.remoting.engine.JnlpProtocol4.pingInterval=30 -jar remoting.jar

验证确认

重新上线 Jenkins Agent:

节点连接状态持久在线,多小时长耗时构建不再突发掉线崩溃。