0
votes

I am trying to read the file from Remote SFTP server using Mule Requestor in MuleSoft version 3.8.5. I can see in the logs connection is getting established with Remote SFTP server but while closing the connection its throwing an error as below :

Error occurred while closing file fileName.dat
java.io.IOException: Pipe closed

I am not sure is it due to file length and connection is getting timed out or anything else.

After Mule requester, Byte-Array to String transformer is there. And exception is thrown there is :

Could not close stream
java.io.IOException: Pipe closed
    at java.io.PipedInputStream.read(PipedInputStream.java:307)
    at java.io.PipedInputStream.read(PipedInputStream.java:377)
    at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2909)
    at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2935)
    at com.jcraft.jsch.ChannelSftp.access$500(ChannelSftp.java:36)
    at com.jcraft.jsch.ChannelSftp$RequestQueue.cancel(ChannelSftp.java:1262)
    at com.jcraft.jsch.ChannelSftp$2.close(ChannelSftp.java:1530)

Any suggestion or help is appreciated.

1

1 Answers

0
votes

This seems to occur when the sftp connection is terminated by the sftp server or cut by e.g. a firewall. I was able to recreate the issue at will using the tcpkill (8) command to terminate the sftp connection that Mule runtime holds open.

Using a pooling profile with eviction times seems to work.

<sftp:config name="Upload_CSV_SFTP_Config" doc:name="SFTP Config" doc:id="88bf2e97-86d2-40fc-af79-536ec838f2d2" >
    <sftp:connection host="${secure::transfer.sftp.hostname}" port="${secure::transfer.sftp.port}" username="${secure::transfer.sftp.username}" knownHostsFile="${secure::transfer.sftp.known_hosts_file}" identityFile="${secure::transfer.sftp.identity_file}" workingDir="${secure::transfer.sftp.directory}" passphrase="${secure::transfer.sftp.passphrase}">
        <reconnection >
            <reconnect frequency="30000" />
        </reconnection>
        <pooling-profile evictionCheckIntervalMillis="60000" initialisationPolicy="INITIALISE_NONE"/>
    </sftp:connection>
</sftp:config>

Mule 4 SFTP Config

Before that, I had tried various combinations of the basic reconnection options on the SFTP config and also the options on the SFTP operation itself, but none seemed to help. One 'hack' that I used at first was to put an SFTP List operation with a path of . (current directory) immediately before the SFTP Read or Write operation.