Agent does not stay connected: java.nio.channels.ClosedChannelException

Today, after I rebooted my agent machine, i went to double click the JNLP agent file as usual, but this time after a brief connection, it then displayed ‘terminated’ It has been working for months without this happening, but now my agent machine can no longer connect to Jenkins. No clue why. The Jenkins admin mentioned the other day, he did upgrade Jenkins… But the connection stopped working for me today after an agent reboot. Once in awhile, the agent connection will flicker from ‘terminated’ to ‘connected’ but in the flash of a hair and it stays in a ‘terminated’ state for the most part.
Any ideas on how to resolve?!?!? Thank you!!!
This is what is displayed in Jenkins when I take a look at the agent node:

Connection was broken

java.nio.channels.ClosedChannelException
at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.onReadClosed(ChannelApplicationLayer.java:238)
at org.jenkinsci.remoting.protocol.ApplicationLayer.onRecvClosed(ApplicationLayer.java:221)
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.onRecvClosed(ProtocolStack.java:825)
at org.jenkinsci.remoting.protocol.FilterLayer.onRecvClosed(FilterLayer.java:288)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.onRecvClosed(SSLEngineFilterLayer.java:179)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.switchToNoSecure(SSLEngineFilterLayer.java:281)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processWrite(SSLEngineFilterLayer.java:501)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.processQueuedWrites(SSLEngineFilterLayer.java:246)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doSend(SSLEngineFilterLayer.java:198)
at org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer.doCloseSend(SSLEngineFilterLayer.java:211)
at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.doCloseSend(ProtocolStack.java:793)
at org.jenkinsci.remoting.protocol.ApplicationLayer.doCloseWrite(ApplicationLayer.java:172)
at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer$ByteBufferCommandTransport.closeWrite(ChannelApplicationLayer.java:340)
at hudson.remoting.Channel.close(Channel.java:1501)
at hudson.remoting.Channel.close(Channel.java:1454)
at jenkins.slaves.DefaultJnlpSlaveReceiver.afterChannel(DefaultJnlpSlaveReceiver.java:178)
at org.jenkinsci.remoting.engine.JnlpConnectionState.fire(JnlpConnectionState.java:337)
at org.jenkinsci.remoting.engine.JnlpConnectionState.fireAfterChannel(JnlpConnectionState.java:428)
at org.jenkinsci.remoting.engine.JnlpProtocol4Handler$Handler.lambda$onChannel$0(JnlpProtocol4Handler.java:334)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
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:750)

If you’re starting the agent with Java Web Start, then you are probably seeing a regression that was introduced in remoting 4.11.2. Fixed in remoting 4.12, with the fix first included in Jenkins 2.335 and scheduled for inclusion in Jenkins LTS 2.332.1 March 9, 2022.

See JENKINS-67000 for more details and the techniques that can be used to work around the issue.

Java web start is not available with Java 11. Jenkins recommends Java 11. Consider replacing your use of Java web start with one of the alternatives described in that issue report.

Hi Mark! Thank you for your response. I am not using Java Web Start, but using this:
Launch agent by connecting it to the other controller…

If you start the agent and a small window appears on the Windows desktop looks like the image in this issue, then you’re using Java web start.

image-2022-02-23-19-08-59-067

The workaround is to start the agent from a batch file on the Windows desktop using the command line that is shown on the Jenkins controller for that agent.

Mark, I appreciate you guiding me in the right direction! Ok, so I grabbed the Run from agent command line text and entered it onto the agent, but now getting this error:

Error: Unable to access jarfile agent.jar

I’m in the directory where the jar file exists: C:\Program Files\jdk1.8.0_301\bin, but after entering the command provided by jenkins, I get Error: Unable to access jarfile agent.jar

You need to download agent.jar (clickable link on that page) to your local computer.

Did that, double-clicked it and nothing happens… hmm…

Think i got it, stay tuned!!!

Mark, Thank you!! It works now! Big life saver!

:tada:

image

Always a good idea to describe your solution after you found it, either because later you’ll end up googling and finding this post again, or helping the next person :slight_smile:

1 Like

In Jenkins, on node, after the exception displays, it has another way to start the agent connection listed. It includes a jar file link that can be clicked and downloaded to your agent. Save it to a folder, then CMD into that folder and then copy the command provided where you were provided the agent link and paste it in the CMD directory where the agent file lives. It now connects!

Hi Team,

We are using Java version- C:\Program Files\Amazon Corretto\jdk11.0.17_8
Jenkins version- Jenkins 2.375.2 and I set connectiontimeout=“600000”
but still giving same exception-

FATAL: command execution failed
java.nio.channels.ClosedChannelException
at jenkins.agents.WebSocketAgents$Session.closed(WebSocketAgents.java:153)
at jenkins.websocket.WebSockets$1.onWebSocketClose(WebSockets.java:88)
at jenkins.websocket.Jetty10Provider$2.onWebSocketClose(Jetty10Provider.java:143)

Please suggest.