Unexpected connection reset when running CLI commands

Article ID:360053420131
1 minute readKnowledge base

Issue

  • After running any CLI command, I get the following stack trace:

javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1533)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:95)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)

Environment

Resolution

There are some reasons why you face a networking error message when you run the jenkins-cli command. One of them is the Connection reset. In this case, the connection between the jenkins-cli command and the Jenkins server is reset by the jenkins-cli if the task requires too much time to be accomplished by the Jenkins server (like for example moving a too large folder of jobs from one controller to another one).

On this kind of error, the solution is using webSocket for the connection. Using webSocket for the connection we will prevent the timeout of the HTTP request and the jenkins-cli will wait for the Jenkins response.

To run the jenkins-cli command using webSocket you only need to add the argument -webSocket to the command. Please, take a look at the following example:

java -jar jenkins-cli.jar -s $JENKINS_URL -auth $USER:$API_TOKEN -webSocket list-plugins

Reference

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.