Connection Issue Between Jenkins Server and Windows Agent

Hi,
I’m facing issue with a Jenkins agent running on a Windows 2022 machine is intermittently disconnecting from the Jenkins server. The agent initially connects successfully, but the connection is terminated after a short period. The error messages on both the server and agent indicate connection issues, but the exact cause remains unclear.

Windows Logs: jenkins-agent.err.log:
Aug 31, 2024 8:05:24 AM io.jenkins.remoting.shaded.org.glassfish.tyrus.container.jdk.client.ClientFilter processError
SEVERE: Connection error has occurred
java.io.IOException: The I/O operation has been aborted because of either a thread exit or an application request
** at java.base/sun.nio.ch.Iocp.translateErrorToIOException(Iocp.java:299)**
** at java.base/sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:389)**
** at java.base/java.lang.Thread.run(Thread.java:840)**

Aug 31, 2024 8:05:24 AM hudson.remoting.Launcher$CuiListener status
INFO: Read side closed
Aug 31, 2024 8:05:24 AM hudson.remoting.Launcher$CuiListener status
INFO: Terminated
Aug 31, 2024 8:05:35 AM hudson.remoting.Launcher$CuiListener status
INFO: Performing onReconnect operation.
Aug 31, 2024 8:05:35 AM jenkins.slaves.restarter.JnlpSlaveRestarterInstaller$EngineListenerAdapterImpl onReconnect
INFO: Restarting agent via jenkins.slaves.restarter.WinswSlaveRestarter@24a85935
Aug 31, 2024 8:05:37 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using C:\jenkins\remoting as a remoting work directory
Aug 31, 2024 8:05:37 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to C:\jenkins\remoting
Aug 31, 2024 8:05:37 AM hudson.remoting.Launcher createEngine
INFO: Setting up agent: itf-ja48asuc-95
Aug 31, 2024 8:05:37 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 3248.3250.v3277a_8e88c9b_
Aug 31, 2024 8:05:37 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using C:\jenkins\remoting as a remoting work directory
Aug 31, 2024 8:05:37 AM hudson.remoting.Launcher$CuiListener status
INFO: WebSocket connection open
Aug 31, 2024 8:05:37 AM hudson.remoting.Launcher$CuiListener status
INFO: Connected

In jenkins console log:
Cannot contact : hudson.remoting.ChannelClosedException: Channel “hudson.remoting.Channel@1a8e489b:”: Remote call on failed. The channel is closing down or has closed down

On jenkins Machine: JENKINS_HOME/logs/slaves/machine/agent.log
Inbound agent connected from 10.228.200.21
Remoting version: 3248.3250.v3277a_8e88c9b_
Launcher: JNLPLauncher
Communication Protocol: WebSocket
This is a Windows agent
Agent successfully connected and online
ERROR: Connection terminated
java.nio.channels.ClosedChannelException
at jenkins.agents.WebSocketAgents$Session.closed(WebSocketAgents.java:157)
at jenkins.websocket.WebSockets$1.onWebSocketClose(WebSockets.java:99)
at jenkins.websocket.WebSockets$1.onWebSocketError(WebSockets.java:105)
at jenkins.websocket.Jetty10Provider$2.onWebSocketError(Jetty10Provider.java:174)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler.onError(JettyWebSocketFrameHandler.java:261)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.lambda$closeConnection$2(WebSocketCoreSession.java:284)
at Jenkins Main ClassLoader//org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1469)
at Jenkins Main ClassLoader//org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1488)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker$1.handle(AbstractHandshaker.java:212)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.closeConnection(WebSocketCoreSession.java:284)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.onEof(WebSocketCoreSession.java:254)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.internal.WebSocketConnection.fillAndParse(WebSocketConnection.java:491)
at Jenkins Main ClassLoader//org.eclipse.jetty.websocket.core.internal.WebSocketConnection.onFillable(WebSocketConnection.java:349)
at Jenkins Main ClassLoader//org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
at Jenkins Main ClassLoader//org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at Jenkins Main ClassLoader//org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:421)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
at Jenkins Main ClassLoader//org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
at java.base/java.lang.Thread.run(Thread.java:840)
ERROR: Connection terminated

upgrade to the latest Long-Term Support (LTS) version of Jenkins and utilize SSH to connect the agent.

The issue might be related to network configuration or firewall settings. Ensure that the network configuration between the machines is consistent and that the firewall rules are the same on both Jenkins controllers. Additionally, it could be linked to an existing issue tracked in Jenkins Jira.

To resolve the issue of Jenkins agent on Windows intermittently disconnecting, you can try changing the TCP parameters in the registry as described in the CloudBees troubleshooting guide and then restart the machine. This solution was found effective for a similar issue.

also look at this -

also make agene online as much as possible you can do that from here:
Navigate to Jenkins >> Manage Jenkins >> Manage Nodes >> your node >> Configure. Change the Availability setting from ‘Take this agent online when in demand, and offline when idle’ to ‘Keep this agent online as much as possible’.

Hi @mushon-okami,

Thanks for your response. I’ve tried and checked all the points you suggested, but unfortunately, none of them have resolved the issue.

The jobs are working correctly with Windows 2019 agents, but we are encountering problems specifically with the Windows 2022 agents. Everything was working fine prior to upgrading to the latest Jenkins LTS version. However, after the upgrade, the issue started appearing within 2-3 days. Even tried downgrading to previous working version but same issue persists