我不确定我的问题是在还是JCraft的Jsch中。我在服务器上有一个应用程序,它接收文件并使用SFTP和会话池将它们放在另一个服务器上。我经常收到木桩的痕迹,一开始是:
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...并以下列例外之一结束:
Caused by: com.jcraft.jsch.JSchException: session is down
at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:762)或
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)或
Caused by: com.jcraft.jsch.JSchException: channel is not opened.
at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765)或
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 这些例外情况通常发生在群体中。例如,我可能会在一分钟内连续下降三四次会话。他们有时也是混合的,所以也许我会得到频道是不开放的,一个会话是关闭的。有时候,它可以很好地工作,而不会抛出异常。
我的豆子:
<bean id="cachingSessionFactory"
class="org.springframework.integration.file.remote.session.CachingSessionFactory">
<constructor-arg ref="sftpSessionFactory" />
</bean>
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<constructor-arg name="isSharedSession" value="true"/>
<property name="host" value="${SERVER}" />
<property name="port" value="22" />
<property name="user" value="${USER}" />
<property name="privateKey" value="${KEYPATH}" />
<property name="sessionConfig" ref="props"/>
</bean>它连接到的服务器的maxSessions设置为30,连接超时时间为6分钟。在过去的几天里,我一直试图调试错误,但似乎无法重现它们。
发布于 2015-11-16 17:50:25
多线程是我的问题所在。我的应用程序将收到一次推送多个文件的请求(比如20+)。问题是会话将过时,但是现在20+线程正在尝试创建一个新会话。它所触及的服务器一次只允许6个sftp连接。
我的解决方案是通过添加
<property name="serverAliveInterval" value="60000" />吃我的豆子。这阻止了连接变得陈旧,缺点是它总是连接(占用资源)。我认为,如果我想解决线程问题,就必须删除Spring,直接使用Jsch。
https://stackoverflow.com/questions/32788255
复制相似问题