Jenkins Agent restart every 5 minutes

Hi everyone,

I’m running into an issue with a Jenkins agent on a Windows desktop PC. The agent seems to disconnect and restart every 5 minutes, which is a major problem because we rely on it to run nightly tests. Unfortunately, this intermittent restarting often causes the tests to fail mid-execution.

Environment Details:

  • Jenkins version: 2.414.3 (hosted on an Azure VM)
  • Agent system: Windows desktop PC
  • Java version: OpenJDK 17.0.10 (2024-01-16 release)
  • Connection type: JNLP4-connect protocol

this is from jenkins agent log

Remoting version: 3131.vf2b_b_798b_ce99
Launcher: JNLPLauncher
Communication Protocol: JNLP4-connect
This is a Windows agent
ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 62-90-105-81.bb.netvision.net.il/62.90.105.81:55849
		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
		at hudson.remoting.Channel.call(Channel.java:1000)
		at hudson.FilePath.act(FilePath.java:1283)
		at org.jenkinsci.plugins.envinject.EnvInjectComputerListener.onOnline(EnvInjectComputerListener.java:144)
		at hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:747)
		at jenkins.slaves.DefaultJnlpSlaveReceiver.afterChannel(DefaultJnlpSlaveReceiver.java:176)
		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:335)
		at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
		at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
		at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
		at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
		at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.lang.reflect.InaccessibleObjectException: Unable to make private native java.lang.reflect.Field[] java.lang.Class.getDeclaredFields0(boolean) accessible: module java.base does not "opens java.lang" to unnamed module @32bca962
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at org.jenkinsci.plugins.envinject.service.EnvInjectMasterEnvVarsSetter.getModifiers(EnvInjectMasterEnvVarsSetter.java:29)
	at org.jenkinsci.plugins.envinject.service.EnvInjectMasterEnvVarsSetter.call(EnvInjectMasterEnvVarsSetter.java:55)
	at org.jenkinsci.plugins.envinject.service.EnvInjectMasterEnvVarsSetter.call(EnvInjectMasterEnvVarsSetter.java:19)
	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
	at hudson.remoting.Request$2.run(Request.java:377)
	at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:125)
	at java.base/java.lang.Thread.run(Thread.java:840)
Agent successfully connected and online
ERROR: Connection terminated
java.nio.channels.ClosedChannelException
	at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:155)
	at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:180)
	at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:789)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

It looks like this is being caused by the Env Inject plugin. Do you have the latest version installed on your controller? Are you actively using Env Inject? If not, you could uninstall it and see if that helps.

we use the plugin.
i also thought it might cause issues but i need to test the update plugin on seperate test jenkins to make sure it wont mess things up since we use a bit old version of jenkins.

The env inject is not the cause for termination of the channel. You should read the upgrade guide for 2.479.1 Upgrading to Jenkins LTS 2.479.x. There is an explanation how you need to adjust the call for starting the agent java process to avoid the problem. This explanation applies also for you Jenkins version as it is related to Java 17.

I will test this, but it won’t be easy :slight_smile: We rely on some quite old plugins that I am not so sure are compatible with new versions.

i am getting alot of issues with our current plugins.
for example i have 2 plugins that i did manage to downgrade to make them work:
Git Parameter - Version 0.9.19
Rebuilder - Version 320.v5a_0933a_e7d61
those two in the new version stopped working correctly (specifically Git parameter didnt show anything).

this is on the jenkins server and not the agent
this is after updating all plugins and the jenkins to 2.479.2

but the current issue i am seeing is in
Project Inheritance Plugin - Version 21.04.03
i tried to downgrade the version did even more issues.
when i try to build a project i am getting ill make it short since its a big error

java.lang.NoSuchMethodError: 'void hudson.model.ParametersDefinitionProperty._doBuild(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse, jenkins.util.TimeDuration)'
	at PluginClassLoader for project-inheritance//hudson.plugins.project_inheritance.projects.InheritanceProject.doBuildInternal(InheritanceProject.java:1857)
	at PluginClassLoader for project-inheritance//hudson.plugins.project_inheritance.projects.InheritanceProject.doBuild(InheritanceProject.java:1801)
	at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuild(ParameterizedJobMixIn.java:411)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:484)
Caused: java.lang.reflect.InvocationTargetException

this is the second error i see.
java.lang.NoSuchMethodError: 'void hudson.model.ParametersDefinitionProperty._doBuild(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse, jenkins.util.TimeDuration)'
	at PluginClassLoader for project-inheritance//hudson.plugins.project_inheritance.projects.InheritanceProject.doBuildInternal(InheritanceProject.java:1857)
	at PluginClassLoader for project-inheritance//hudson.plugins.project_inheritance.projects.InheritanceProject.doBuild(InheritanceProject.java:1801)
	at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuild(ParameterizedJobMixIn.java:411)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:484)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:497)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:218)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:140)
	at org.kohsuke.stapler.MetaClass$12.doDispatch(MetaClass.java:686)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:61)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:800)
Caused: jakarta.servlet.ServletException

well a little update.
it seems jenkins 2.479.X breaks too much plugins we use.
and 2.462.3 seems to be quite stable for our plugin use (besides Rebuilder plugin which i fixed manually).

i hope it will help with the issue on the agent.

no it didnt help and the agent still crashes every 5 - 10 minutes
its also messing the Git because of this


Inbound agent connected from X
Remoting version: 3248.3250.v3277a_8e88c9b_
Launcher: JNLPLauncher
Communication Protocol: JNLP4-connect
This is a Windows agent
Agent successfully connected and online
ERROR: Connection terminated
java.nio.channels.ClosedChannelException
	at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:155)
	at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:180)
	at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:789)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Inbound agent connected from X
Remoting version: 3248.3250.v3277a_8e88c9b_
Launcher: JNLPLauncher
Communication Protocol: JNLP4-connect
This is a Windows agent
Agent successfully connected and online
ERROR: Connection terminated
java.nio.channels.ClosedChannelException
	at org.jenkinsci.remoting.protocol.NetworkLayer.onRecvClosed(NetworkLayer.java:155)
	at org.jenkinsci.remoting.protocol.impl.NIONetworkLayer.ready(NIONetworkLayer.java:180)
	at org.jenkinsci.remoting.protocol.IOHub$OnReady.run(IOHub.java:789)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Inbound agent connected from X
Remoting version: 3248.3250.v3277a_8e88c9b_
Launcher: JNLPLauncher
Communication Protocol: JNLP4-connect
This is a Windows agent
Agent successfully connected and online