Error occurred while closing file from remote server in MuleSoft - sftp

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.

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.

Related

Continuously running send pipeline instance

An instance of a BizTalk send pipeline has started to run continuously. On 09/12/2021 an attempt was made to send a file via SFTP, which retried several times but ultimately failed due to a network issue. The error from the event logs is:
The adapter failed to transmit message going to send port "Deliver Outgoing - SFTP" with URL "sftp://xxx.xxxxxx.co.nz:22/To_****/%SourceFileName%". It will be retransmitted after the retry interval specified for this Send Port. Details:"WinSCP.SessionRemoteException: Network error: Software caused connection abort.
For some reason BizTalk made another send attempt at 1:49pm on 10/12/2021 which succeeded as confirmed by the administrator of the SFTP site. Despite this, BizTalk continued making intermittent send attempts and the pipeline instance is still running. The same file has been sent 4 times to the SFTP server.
The pipeline instance in theory should have suspended at 9:47pm on 09/12/2021. I have been able to confirm definitively whether anybody resumed it, but it seems unlikely at this stage. In any case, after sending successfully the pipeline instance should have terminated and should not be re-executing intermittently.
Does anybody know what could account for this behaviour? This is occurring on BTS2020 with CU2 applied.
I've sent messages over SFTP where the WinSCP interpretation of the date-modified attribute doesn't work with a specific type of SFTP server.
With the WinSCP GUI a dialogue box appears and you can disregard this error, but this option isn't available with BizTalk's GUI. This error appears when a file with the same filename already exists on the server and is supposed to be overwritten.
My solution was to create a pipeline component that removed %SourceFileName% on the server. The pipeline component (just like WinSCP GUI) can disregard the modified-date.

Sharepoint : The underlying connection was closed: An unexpected error occurred on a send. but not al the time

I am trying to upload files to sharepoint with a uploadsession,
https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
It works -i create the uploadsession - and with the received url i upload the file.
but it only works some minutes in a hour.
Creating and receiving the data for the uploadsession is no problem but uploading the file i get for the most time the error: The underlying connection was closed: An unexpected error occurred on a send.
StackTrace: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. -
I dont think its TLS1.2 related because it sometimes works?
It could be TLS1.2 related. The similar issue was discussed here: https://github.com/pnp/pnpframework/issues/336. Windows 2012 R2 and worked intermittently.
Make sure the server supports one of supported cyphers:
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_DHE_RSA_WITH_AES_256_GCM_SHA38
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256

com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read

While connecting SFTP I am getting following error.
com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
Please guide me,
Actually i think the answer is trivial. You are not able to open a stream i.e. the sftp connexion is not estabmlished sucessfully. Check wit IT team or support if there is firewalls or so and that can see you arriving on the server.

JSch session.connect() hungs with CoreFTP

I have CoreFTP configured for localhost and the next code:
JSch.setLogger(new MyJschLogger()); //class for console output
Session session = jsch.getSession("user", "localhost", 21);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword("password");
session.connect();
when program achieves connect(), two messages appear at console output:
INFO: Connecting to localhost port 21
INFO: Connection established
...and nothing more happens. After some minutes, connection is closed by foreign host exception appears.
Why?
Thanks for all!
Port 21 is the normal port for FTP. JSch is only an SSH client, with support for SFTP in the ChannelSFTP class. JSch knows nothing about FTP (and SFTP is unrelated to FTP, other than by name and that it allows similar things).
You need to setup your server to use the SSH protocol (usually on port 22, but you can use any port, as long as you use the same port on the client). See the documentation - I think you have to check the SSH check box.
Also, if your code is nothing more than what you posted, then nothing more than connecting will happen. To transfer files, you will need to open a ChannelSFTP, and issue the right commands (e.g. call one or more of the put/get methods).
I also faced the similar issue:
"ERROR 2016-04-27 15:05:16,489 [CollectionThreadPool-0] com.dell.supportassist.collector.cli.executor.SSHExecutor: com.jcraft.jsch.JSchException: connection is closed by foreign host"
In my case, channel was getting closed randomly. And when we are trying to re-connect the channel then it was not re-connecting and failing.
This was happening due to looping logic while connecting, so I tried to connect the session without channel by calling method connectWithoutOpenChannel instead of connectinternal(). This resolved my issue.

ODBC Driver General error: attempted two active database requests

I'm using ASP.NET 2.0 to connect to a Sybase SQL Anywhere 5 server. And I get this error sporadically. It just happens sometimes. The error message is:
ERROR [HY000] [Sybase][ODBC Driver]General error: attempted two active database requests
Exception Details: System.Data.Odbc.OdbcException: ERROR [HY000] [Sybase][ODBC Driver]
General error: attempted two active database requests
Anyone has any experience with this problem?
The error message means that you attempted to run two queries at the same time using the same database connection.
Are you trying to use the same database connection for all requests? The requests are handled by several threads, so each request needs to have it's own database connection.
Sounds like you're reusing the same connection for multiple commands. Check that you properly dispose of the connections after each command/batch of commands and that all new commands get a new connection.

Resources