Ant SCP/SSH Task Hangs Or Never Disconnects

If you're using the scp or ssh tasks with ant, you may run into a problem where part way during the upload or never disconnecting after the command completes for the ssh task. There are a couple of possible causes:

  1. The scp problem is almost certainly caused by using ant 1.7.0 or below and jsch 0.1.30 or above. You could upgrade to the latest nightly of ant1 but it's probably easier to just drop back to jsch 0.1.29 which is what ant was developed against and works nicely. Bug 41090 contains the gory details.
  2. If the command you're executing with the ssh task starts a background service or otherwise leaves a process running, that may be the cause of the problem. You can add 'shopt -s huponexit' to your /etc/profile, .bashrc or somewhere like that. I must admit, I'm somewhat vague on the exact details of what that does but the basic idea seems to be to signal any background processes that bash is exiting and then not wait for them to complete (which allows your ssh connection to close). If you're starting a server they'll probably ignore the hup signal it sends and if not, use the nohup command.

Hopefully that will be the last I'll see of that issue.

1 - which seems to mean compiling from source at the moment, since the nightly build directory the Ant website links to is empty

4 Responses to “Ant SCP/SSH Task Hangs Or Never Disconnects”

  1. David Says:

    We intermittently had a similar problem at work. Interactive ssh with X forwarding, though.

    With ssh -vvv we tracked it to an xauth process being started and not exiting every time, and when PuTTY clients exited the xauth process would go to 100% CPU. I think we eventually tracked it down to something about people’s home areas being auto-mounted from a new Linux box, and xauth was looking to read or write some magic cookie and it got all upset.


  2. Mr Frosti Says:

    Thanks a million for this post. I was going crazy thinking it was my limited understanding of Ant. With Ant 1.7.0, jsch .1.29 works perfectly, as you mentioned. Btw, the direct link to this older release is here: http://sourceforge.net/project/downloading.php?group_id=64920&use_mirror=easynews&filename=jsch-0.1.29.jar&96256293


  3. Deploy file to Sourceforge with an ant task « Java and more … Says:

    [...] with an ant task Filed under: Java, News — Peter @ 6:35 pm After studying the workaround I can now deploy a file to my sourceforge directory. Now I don’t need to upload the file [...]


  4. n/a Says:

    Thank you so much for this post — reverting back to use jsch-0.1.29.jar worked! (instead of jsch-0.1.39.jar)


Leave a Reply

Alternatively, subscribe to the Atom feed.