1
votes

I'm using spring-integration 2.1 with an SFTP outbound-channel-adapter component to transfer files to a remote location. Intermittently, I'm getting the following exception:

Error handling message for file <file_name>  _org.springframework.integration.MessageDeliveryException: Error handling message for file <file_name>
... stack was trimmed to be contained in a single post...
Caused by: org.springframework.integration.MessagingException: Failed to write to '<file_name>.writing' while uploading the file
      at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.sendFileToRemoteDirectory(FileTransferringMessageHandler.java:227)
      at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.handleMessageInternal(FileTransferringMessageHandler.java:136)
      ... 225 more
Caused by: org.springframework.core.NestedIOException: failed to write file; nested exception is 4: java.io.IOException: Pipe closed
      at org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:109)
      at org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession.write(CachingSessionFactory.java:147)
      at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.sendFileToRemoteDirectory(FileTransferringMessageHandler.java:222)
      ... 226 more
Caused by: 4: java.io.IOException: Pipe closed
      at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:623)
      at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:480)
      at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:439)
      at org.springframework.integration.sftp.session.SftpSession.write(SftpSession.java:106)
      ... 228 more
Caused by: java.io.IOException: Pipe closed
      at java.io.PipedInputStream.read(PipedInputStream.java:291)
      at com.jcraft.jsch.Channel$MyPipedInputStream.updateReadSide(Channel.java:397)
      at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:493)
      ... 231 more

I've seen posts dealing with this kind of error, but there wasn't any answer.

I suppose the SFTP server terminates the connection due to inactivity (basic timeout), but why doesn't Spring Integration try to establish a new connection?

2

2 Answers

0
votes

I suggest you upgrade to a newer version of Spring Integration; the current version is 4.0.4.

Or you can simply disable session caching.

We rewrote session caching a couple of years ago (in 2.2; current version 2.2.6) and it now checks for a stale session when a cached session is retrieved from the cache.

The cache-sessions attribute is no longer available; you have to wrap the session factory in a CachingSessionFactory to cache sessions now.

0
votes

Restart of a Java service where jsch is executed solved problem for me.

In my case there was a change of server's host ssh key, for instance it is a strange policy on Azure VMs that forces periodic key update.