Dolphin
Dolphin

Reputation: 38601

java.nio.channels.ClosedChannelException when start jenkins slave in kubernetes

I am using jenkins master-slave model to build a project in kubernetes(install using helm), this is my simple build script to compile the java project:

#!/usr/bin/env bash


set -u

set -e

set -x

./gradlew clean :eureka-service:build -x test

when I execute this build script in jenkins slave node, shows error:

Started by user admin
Running as SYSTEM
Agent default-j0463 is provisioned from template default
---
apiVersion: "v1"
kind: "Pod"
metadata:
  labels:
    jenkins/jenkins-jenkins-slave: "true"
    jenkins/label: "jenkins-jenkins-slavex"
  name: "default-j0463"
spec:
  containers:
  - args:
    - "********"
    - "default-j0463"
    env:
    - name: "JENKINS_SECRET"
      value: "********"
    - name: "JENKINS_TUNNEL"
      value: "jenkins-agent:50000"
    - name: "JENKINS_AGENT_NAME"
      value: "default-j0463"
    - name: "JENKINS_NAME"
      value: "default-j0463"
    - name: "JENKINS_AGENT_WORKDIR"
      value: "/home/jenkins"
    - name: "JENKINS_URL"
      value: "http://jenkins.infrastructure.svc.cluster.local:8080"
    image: "jenkins/jnlp-slave:3.27-1"
    imagePullPolicy: "IfNotPresent"
    name: "jnlp"
    resources:
      limits:
        memory: "512Mi"
        cpu: "512m"
      requests:
        memory: "512Mi"
        cpu: "512m"
    tty: false
    volumeMounts:
    - mountPath: "/home/jenkins"
      name: "workspace-volume"
      readOnly: false
    workingDir: "/home/jenkins"
  nodeSelector:
    kubernetes.io/os: "linux"
  restartPolicy: "Never"
  serviceAccount: "default"
  volumes:
  - emptyDir:
      medium: ""
    name: "workspace-volume"

Building remotely on default-j0463 (jenkins-jenkins-slave) in workspace /home/jenkins/workspace/eureka-service
Installer "Extract *.zip/*.tar.gz" cannot be used to install "jdk11" on the node "default-j0463"
No credentials specified
Installer "Extract *.zip/*.tar.gz" cannot be used to install "jdk11" on the node "default-j0463"
Cloning the remote Git repository
Cloning repository https://github.com/jiangxiaoqiang/retire.git
 > git init /home/jenkins/workspace/eureka-service # timeout=10
Fetching upstream changes from https://github.com/jiangxiaoqiang/retire.git
 > git --version # timeout=10
 > git --version # 'git version 2.11.0'
 > git fetch --tags --progress -- https://github.com/jiangxiaoqiang/retire.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/jiangxiaoqiang/retire.git # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/jiangxiaoqiang/retire.git # timeout=10
Fetching upstream changes from https://github.com/jiangxiaoqiang/retire.git
 > git fetch --tags --progress -- https://github.com/jiangxiaoqiang/retire.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Installer "Extract *.zip/*.tar.gz" cannot be used to install "jdk11" on the node "default-j0463"
Checking out Revision 370d36c72460362fad2d21135d68963b3ec8ff75 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 370d36c72460362fad2d21135d68963b3ec8ff75 # timeout=10
Commit message: "[feature] tweak"
 > git rev-list --no-walk 370d36c72460362fad2d21135d68963b3ec8ff75 # timeout=10
Installer "Extract *.zip/*.tar.gz" cannot be used to install "jdk11" on the node "default-j0463"
[eureka-service] $ /bin/sh -xe /tmp/jenkins4274366632085338330.sh
+ cd /home/jenkins/workspace/eureka-service/eureka-service
+ ./script/docker-deploy-impl.sh
+ ./gradlew clean :eureka-service:build -x test
Downloading https://services.gradle.org/distributions/gradle-6.5.1-bin.zip
.........10%..........20%..........30%..........40%.........50%..........60%..........70%..........80%.........90%..........100%

Welcome to Gradle 6.5.1!

Here are the highlights of this release:
 - Experimental file-system watching
 - Improved version ordering
 - New samples

For more details see https://docs.gradle.org/6.5.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
FATAL: command execution failed
java.nio.channels.ClosedChannelException
    at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:154)
    at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:142)
    at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:795)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused: java.io.IOException: Backing channel 'JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922' is disconnected.
    at hudson.remoting.RemoteInvocationHandler.channelOrFail(RemoteInvocationHandler.java:216)
    at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:285)
    at com.sun.proxy.$Proxy89.isAlive(Unknown Source)
    at hudson.Launcher$RemoteLauncher$ProcImpl.isAlive(Launcher.java:1147)
    at hudson.Launcher$RemoteLauncher$ProcImpl.join(Launcher.java:1139)
    at hudson.tasks.CommandInterpreter.join(CommandInterpreter.java:155)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1880)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:428)
FATAL: Unable to delete script file /tmp/jenkins4274366632085338330.sh
java.nio.channels.ClosedChannelException
    at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:154)
    at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:142)
    at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:795)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused: hudson.remoting.ChannelClosedException: Channel "hudson.remoting.Channel@52ebddbf:JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922": Remote call on JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922 failed. The channel is closing down or has closed down
    at hudson.remoting.Channel.call(Channel.java:991)
    at hudson.FilePath.act(FilePath.java:1069)
    at hudson.FilePath.act(FilePath.java:1058)
    at hudson.FilePath.delete(FilePath.java:1543)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:123)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1880)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:428)
Build step 'Execute shell' marked build as failure
FATAL: Channel "hudson.remoting.Channel@52ebddbf:JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922": Remote call on JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922 failed. The channel is closing down or has closed down
java.nio.channels.ClosedChannelException
    at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:154)
    at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:142)
    at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:795)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused: hudson.remoting.ChannelClosedException: Channel "hudson.remoting.Channel@52ebddbf:JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922": Remote call on JNLP4-connect connection from 10.11.125.137/10.11.125.137:45922 failed. The channel is closing down or has closed down
    at hudson.remoting.Channel.call(Channel.java:991)
    at hudson.Launcher$RemoteLauncher.kill(Launcher.java:1083)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:510)
    at hudson.model.Run.execute(Run.java:1880)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:428)
Finished: FAILURE

I am already trying the test command and shows the podtemplate connection is success.I am trying to increse the podtemplate memory to 512MB,the project is small and only have few code.where is the problem and what should I do to fix?

Upvotes: 2

Views: 6599

Answers (1)

Dolphin
Dolphin

Reputation: 38601

I finally find out is the resource is not enough for build. so I tweak config and increse the template pod resource from 512Mi to 1024Mi:

* Request Memory:1024Mi
* Limit Memory:1024Mi

works.

Upvotes: 2

Related Questions