title: Different JSchException thrown when using Spring Integration
body: <p>I'm unsure if my issue resides in Spring Integration or JCraft's Jsch. I have an application on a server that takes in files and places them on another server using SFTP and session pools. Ever so often I receive stake traces that start with:</p>
  
  <pre><code>     java.lang.IllegalStateException: failed to create SFTP Session
       Caused by: java.lang.IllegalStateException: failed to create SFTP Session
       Caused by: java.lang.IllegalStateException: failed to connect...
  </code></pre>
  
  <p>and ends with one of the following exceptions:</p>
  
  <pre><code>    Caused by: com.jcraft.jsch.JSchException: session is down
      at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:762)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>    Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 This session would exceed your concurrent session limit. Please disconnect one or more of your existing sessions and try again. 
      at com.jcraft.jsch.Session.read(Session.java:996)
      at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:198)
      at com.jcraft.jsch.Session.connect(Session.java:463)
      at com.jcraft.jsch.Session.connect(Session.java:183)
      at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:263)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Caused by: com.jcraft.jsch.JSchException: channel is not opened.
      at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Caused by: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 2 FlowSshPacketDecoder: received a higher-level packet before first key exchange is done 
      at com.jcraft.jsch.Session.read(Session.java:996)
      at com.jcraft.jsch.Session.connect(Session.java:323)
      at com.jcraft.jsch.Session.connect(Session.java:183)
      at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:263)
      ... 45 more 
  </code></pre>
  
  <p>These exceptions usually happen in groups. For example, I might get Session is down three or four times in a row within a minute. They sometimes are also mixed, so maybe I'll get channel is not open with a session is down. Sometime, it works perfectly without throwing an exception.</p>
  
  <p>My bean:</p>
  
  <pre><code>&lt;bean id="cachingSessionFactory"
      class="org.springframework.integration.file.remote.session.CachingSessionFactory"&gt;
      &lt;constructor-arg ref="sftpSessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sftpSessionFactory"
      class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"&gt;
      &lt;constructor-arg name="isSharedSession" value="true"/&gt;
      &lt;property name="host" value="${SERVER}" /&gt;
      &lt;property name="port" value="22" /&gt;
      &lt;property name="user" value="${USER}" /&gt;
      &lt;property name="privateKey" value="${KEYPATH}" /&gt;
      &lt;property name="sessionConfig" ref="props"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The server it is connecting to has maxSessions set to 30 and a connection timeout of 6 minutes. I've spent the past couple of days trying to debug the errors, but can't seem to reproduce them.</p>