Jenkins Agent Can't Connect: Fix ACK Sequence Error
In this article
If your Jenkins agent fails to connect with an "incorrect acknowledgement sequence" error, it usually means the agent process and the controller are out of sync—often due to a stale agent JAR, a mismatched secret, or network interference. The fix is to cleanly restart the agent with the latest JAR and verify the connection settings. Below is a step-by-step guide to resolve it.
What You'll Need
- Administrative access to the Jenkins controller (web UI).
- Access to the agent machine (command line or remote desktop).
- The agent's name and its secret (found in the node configuration).
- Network connectivity between agent and controller (check firewall rules).
Step-by-Step
- Stop the agent process. On the agent machine, terminate the running agent. If it's a service, stop it (e.g.,
systemctl stop jenkins-agenton Linux, or stop the Windows service). If it's a foreground process, press Ctrl+C. - Delete the old agent JAR file. The agent downloads a JAR (usually
agent.jar) from the controller. Remove it from the agent's working directory to force a fresh download. This eliminates version mismatches. - Get the latest agent connection command. Log into the Jenkins controller web UI. Go to Manage Jenkins > Nodes (or Manage Jenkins > Manage Nodes). Click on the agent node that's failing. On the node's page, look for a section titled "Launch agent" or "Agent command". Copy the command—it typically looks like:
java -jar agent.jar -url http://your-controller:8080/ -secret @secret-file -name agent-name
If you don't see a command, click "Generate" or "Show" to reveal it. - Verify the secret. The secret in the command must match the one stored on the controller. If you're unsure, go to the node's configuration page (click the gear icon next to the node), and you'll find the secret field. You can regenerate it there, but note that will invalidate any existing agent connections.
- Re-launch the agent. On the agent machine, run the copied command from the directory where you want the agent to work. Make sure the JAR is downloaded fresh (the command will do that automatically if it's not present). Watch the output for the connection attempt.
- Check the controller log. If the error persists, look at the Jenkins controller logs (usually
jenkins.login the Jenkins home directory). Search for the agent's name and the error message. This often reveals the exact cause—like a timestamp mismatch or a network proxy issue. - Restart the controller if needed. In rare cases, the controller's TCP port for agents (default 50000) might be stuck. Restarting the Jenkins service on the controller can clear it. Do this only if you have maintenance downtime.
Common Mistakes
- Using an old agent.jar: The JAR must match the controller's version. If you copy it from another machine, it may be outdated.
- Copy-pasting the command incorrectly: The secret might be truncated or contain special characters that get mangled. Type it manually or use the "copy" button if available.
- Running the agent from the wrong directory: The agent may need write permissions in the working directory. If it can't write, the handshake fails.
- Firewall blocking port 50000: The agent connects to the controller's TCP port (default 50000) for the actual communication. If that port is blocked, you'll get connection errors, possibly including the ACK sequence issue.
- Multiple agent instances: If an old agent process is still running, it may hold the connection. Ensure only one instance runs.
Tips
- Use the "Launch agent via SSH" method if you can't run the command manually—it's more reliable for remote machines.
- Set up the agent as a service (systemd, Windows service) so it restarts automatically. The command can be wrapped in a service script.
- If you use a proxy, make sure the agent JVM has the proxy settings configured via
-Dhttp.proxyHostand-Dhttp.proxyPortarguments. - Regularly update the agent JAR by restarting the agent—it auto-downloads the latest version.
- Check the controller's system clock and the agent's clock. A large time skew (more than a few minutes) can cause handshake failures.
Troubleshooting
If the error persists after restarting:
- Check the agent's logs. The agent prints detailed connection errors to the console. Look for lines mentioning "ack" or "handshake".
- Verify the controller's URL is reachable from the agent: run
curl http://your-controller:8080from the agent machine. If it fails, it's a network issue. - Try connecting to the TCP port directly:
telnet your-controller 50000. If that fails, the port is closed or the controller isn't listening. - If you're using a reverse proxy (like nginx) in front of Jenkins, ensure it's configured to forward the TCP port 50000, not just HTTP.
- Look at the Jenkins system log for errors like "Failed to connect" or "Connection reset". That may point to a firewall or a security plugin (like the "Authorization" plugin) blocking the connection.
- As a last resort, delete the agent node from Jenkins and recreate it with a new name and secret. Then relaunch.
Frequently Asked Questions
What exactly does "incorrect acknowledgement sequence" mean?
It means the agent and controller are not following the expected protocol during the initial handshake. This often happens when the agent sends data that the controller doesn't expect, usually due to version mismatch or corrupted state.
Do I need to update the agent JAR manually?
No. The agent command automatically downloads the correct JAR from the controller. Just delete the old one and run the command again.
Can I use the same secret for multiple agents?
No. Each agent has a unique secret. Reusing one will cause conflicts and connection failures.
What if I can't access the agent machine directly?
If the agent runs as a service, you can restart it via the service manager (e.g., systemctl restart jenkins-agent). If it's a container, restart the container.
Does the controller need to be restarted?
Usually not, but if you've tried everything and the error persists, a controller restart can clear stuck connections. Do it during a maintenance window.
Is there a way to test the connection without launching the full agent?
Yes, you can use curl to check the HTTP endpoint, and telnet to check the TCP port. But the full agent launch is the only real test.