Java error on jenkins while trying to add jenkins agent

java.io.IOException: error=0, Failed to exec spawn helper: pid: 1959574, exit value: 1
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
Caused: java.io.IOException: Cannot run program "ssh": error=0, Failed to exec spawn helper: pid: 1959574, exit value: 1
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at hudson.slaves.CommandLauncher.launch(CommandLauncher.java:163)
	at hudson.slaves.SlaveComputer.lambda$_connect$0(SlaveComputer.java:297)
	at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
	at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:80)
	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 java.base/java.lang.Thread.run(Thread.java:840)

you need to provide more information if someone should help.
How did you configure the agent? From the stacktrace it looks as if you used the Command Agent Launcher plugin to launch the agent but then you want to make an ssh call. For ssh you better use the SSH Build Agents plugin

I think that I remember a change in a Java upgrade that caused the Java spawn helper script to change name or otherwise become different between one Java update and the next. You might want to be sure that the agent has been stopped and restarted since the most recent Java patch was applied.

Refer to Jenkins issue: FATAL: command execution failed - #8 by jspiewak for more details.

I configured it using command launch from the jenkins configuration. it will basically run the jar file to add agent in controller.

I am currently using java 11.0.25

Anyway if you still see this problem you will probably need to restart your controller if the assumption from Mark is correct

Please provide more details.
Which Jenkins version are you using?
Which java version are you using to run the controller and which java version for the agent.
How are you trying to run the agent? With CommandLauncher, then please let us know the command you’re trying to run

jenkins version: 2.440.3
Java running on controller : 17.0.11
controller OS: UBUNTU 20.04
java running on agent: 17.0.13
Agent OS: UBUNTU 22.04

launch command: ssh ‘agent ip’ java -jar ~/bin/agent.jar

Also M using “-Djdk.lang.Process.launchMechanism=vfork” at the time of command launch but still not working!!

You do not have (or it is not in the PATH) an SSH CLI in the Jenkins Controller, so when you try to launch the agent with the command ssh IP java -jar ~/bin/agnet.jar, the controller does not find sshin the PATH of the user that runs the Jenkins process.

I have ssh in the controller with that user as well

Java 17.0.11 is over 6 months out of date. I would be surprised if Ubuntu were not trying to update it to the current Java 17.0.13. If Java is upgraded on the controller while the controller is running, then there is a high risk of the “spawn helper” message appearing. If a previous Java upgrade was incomplete or damaged, that might also cause the “spawn helper” message.

Ubuntu 20.04 will be unsupported by the Jenkins project in April 2025. You have less than 6 months before that operating system is unsupported by Jenkins.

Jenkins 2.440.3 has known at least one known critical security vulnerability. Upgrade Jenkins as soon as you can.

Try to use the absolute path instead of only the command

Another point is that it is probably better to use the SSH Build Agents to connect agents with ssh than using the command launcher plugin. It avoids that an external ssh process is started at all.

Can we do something with the agent to fix the issue. As controller is on production. I cannot do anything in that.

Not as far as I can tell. If I am reading the stack trace correctly, the stack trace indicates that the Failed to exec spawn helper is happening on the Jenkins controller. Changes on the agent won’t help.

If the failure is due to a Java upgrade that has happened while the Jenkins controller is running, then I think that means that you should be able to resolve the issue by restarting the Java process that runs the Jenkins controller.