简体   繁体   中英

Quartz job running - Could not connect to SFTP server - connection reset

Modified the descripton I have a quartz job running in that VM and i used to get this error

org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "sftp://reports.staging.companyname.com/".
        at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:107)
        at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.getFileSystem(AbstractOriginatingFileProvider.java:103)
        at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:81)
        at org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:65)
        at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:693)
        at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:621)
        at com.companyname.appname.connector.dropbox.sftp.PseSFTPConnection.doConnect(PseSFTPConnection.java:149)
        at com.companyname.appname.connector.dropbox.sftp.PseSFTPConnection.connect(PseSFTPConnection.java:109)
        at com.companyname.appname.connector.dropbox.sftp.DropboxDaoSFTPImpl.isAvailable(DropboxDaoSFTPImpl.java:183)
        at com.companyname.appname.batch.jobs.DataFileProcessorJob.execute(DataFileProcessorJob.java:46)
        at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
        at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264)
        at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "reports.staging.companyname.com".
        at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:230)
        at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:96)
        ... 17 more
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: Connection reset
        at com.jcraft.jsch.Session.connect(Session.java:565)
        at com.jcraft.jsch.Session.connect(Session.java:183)
        at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:226)
        ... 18 more
sdfFileProcessing_Worker-9 2019-11-04 05:20:03,915 ERROR: com.companyname.appname.connector.dropbox.sftp.DropboxDaoSFTPImpl - Is available

when i use normal Sftp command line utility also getting "Connection reset by peer" "ssh_exchange_identification: read: Connection reset by peer Couldn't read packet: Connection reset by peer" from java code and normal Sftp command -> connection also fails.

root@qa-batch:~# sftp userid_usercontinuation@somedomain.com
ssh_exchange_identification: read: Connection reset by peer
Couldn't read packet: Connection reset by peer
root@qa-batch:~# free -m
             total       used       free     shared    buffers     cached
Mem:          3953       3522        430          0        299       1570
-/+ buffers/cache:       1652       2300
Swap:         2047          6       2041
root@qa-batch:~#

I keep on getting this exception.

The issue is continuously reoccuring, and in the code using finally block properly disconnect the connection. I checked in some of stack overflow forums but they mentioned it might be a heap issue. So i tried stoping the java quartz service, temporarily i am able to connect using sftp cli command (ie,. after 5 mins). But my requirement is the java application should be able to connet to sftp and read a remote file, then process and update to DB.

Usually "Connection reset by peer" means that there is an issue on the other end (SFTP remote server in this case), so the chances are that Quartz Job and Java in general are not "guilty". Probably sometimes you can also check the network for issues but that's not Java...

So in terms of resolution, first of all try connecting with some "non-java" client and see that sometimes you won't be able to connect as well.

After that, there is not much you can do:

  • Retries, you can retry the connection attempt

  • Alternatively, if the business logic makes sense: run the job more frequently so that if one job execution failed to interact with the remote server, pretty quickly another trigger will start and probably you'll be more lucky this time.

I realize that all these are pretty bad workarounds, but again, without a stable connection to the remote part you can't really solve it in Java, sorry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM