title: jenkins-cli build trigger connection times out for long running jobs
body: <p>I use the followig command from udeploy Shell step to invoke a Jenkins job. I need to wait for the job to finish and then continue with further steps in udeploy.</p>
  
  <p>Irrespective of whether i invoke the jenkins job directly from a shell on the server or from a Shell step in Udeploy, the problem is the same.</p>
  
  <p>Cmd:-
  java -jar jenkins-cli.jar -s  -remoting build  -s --username  --password ''</p>
  
  <p>Output of short running jobs ( few mins )</p>
  
  <pre><code>Aug 03, 2018 3:55:09 PM hudson.cli.CLI _main
  WARNING: Failed to authenticate with your SSH keys. Proceeding as anonymous
  Started Job » SleepJob #4
  Completed Job #4 : SUCCESS
  </code></pre>
  
  <p>Output of long running jobs (Not sure exactly where it fails, but have noticed this for a job running for an hour)
  *Jenkins job finishes fine
  *The status returned to the shell is this</p>
  
  <pre><code>Aug 03, 2018 11:42:53 AM hudson.cli.CLI _main
  WARNING: Failed to authenticate with your SSH keys. Proceeding as anonymous
  Started Job #1
  Aug 03, 2018 1:54:36 PM hudson.remoting.SynchronousCommandTransport$ReaderThread run
  SEVERE: I/O error in channel CLI connection to &lt;URL&gt;
  java.net.SocketException: Connection timed out (Read failed)
          at java.net.SocketInputStream.socketRead0(Native Method)
          at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
          at java.net.SocketInputStream.read(SocketInputStream.java:171)
          at java.net.SocketInputStream.read(SocketInputStream.java:141)
          at java.io.FilterInputStream.read(FilterInputStream.java:133)
          at java.io.FilterInputStream.read(FilterInputStream.java:107)
          at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:114)
          at javax.crypto.CipherInputStream.read(CipherInputStream.java:239)
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
          at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
          at hudson.remoting.FlightRecorderInputStream.read(FlightRecorderInputStream.java:91)
          at hudson.remoting.ChunkedInputStream.readHeader(ChunkedInputStream.java:72)
          at hudson.remoting.ChunkedInputStream.readUntilBreak(ChunkedInputStream.java:103)
          at hudson.remoting.ChunkedCommandTransport.readBlock(ChunkedCommandTransport.java:39)
          at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
          at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
  hudson.remoting.RequestAbortedException: java.net.SocketException: Connection timed out (Read failed)
          at hudson.remoting.Request.abort(Request.java:329)
          at hudson.remoting.Channel.terminate(Channel.java:992)
          at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:96)
          Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to CLI connection to &lt;URL&gt;
                  at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1693)
                  at hudson.remoting.Request.call(Request.java:192)
                  at hudson.remoting.Channel.call(Channel.java:907)
                  at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:281)
                  at com.sun.proxy.$Proxy3.main(Unknown Source)
                  at hudson.cli.CLI.execute(CLI.java:380)
                  at hudson.cli.CLI._main(CLI.java:644)
                  at hudson.cli.CLI.main(CLI.java:426)
  Caused by: java.net.SocketException: Connection timed out (Read failed)
          at java.net.SocketInputStream.socketRead0(Native Method)
          at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
          at java.net.SocketInputStream.read(SocketInputStream.java:171)
          at java.net.SocketInputStream.read(SocketInputStream.java:141)
          at java.io.FilterInputStream.read(FilterInputStream.java:133)
          at java.io.FilterInputStream.read(FilterInputStream.java:107)
          at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:114)
          at javax.crypto.CipherInputStream.read(CipherInputStream.java:239)
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
          at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
          at hudson.remoting.FlightRecorderInputStream.read(FlightRecorderInputStream.java:91)
          at hudson.remoting.ChunkedInputStream.readHeader(ChunkedInputStream.java:72)
          at hudson.remoting.ChunkedInputStream.readUntilBreak(ChunkedInputStream.java:103)
          at hudson.remoting.ChunkedCommandTransport.readBlock(ChunkedCommandTransport.java:39)
          at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
          at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
  </code></pre>
  
  <p>For test purpose, there is no idle time even set on the slave configuration.</p>
  
  <p>The error message is thrown 12 mins after the jenkins job finishes. Even if the job would take 4 hrs, it executes the job successfully and at the end it throws the error. </p>
  
  <p>If there is a connectivity drop, then the error would appear when the problem happens and not always after the job finishes. </p>
  
  <p>What should i check in network/firewall to fix this ? We do not have any specific port set for the slave connection. </p>
  
  <p>tcpdump is very large for larger duration to check when eactly it drops. 
  What are some better ways to troubleshoot the issue.</p>