Hello,
I am using Jsch 0.1.54.
I have an application that never ignores java.lang.InterruptedException.
When I interrupt my Thread which makes Jsch SFTP calls, my interrupt is ignored in get() method and it continues to work; and then, it hangs in rm() call. If I check Thread.currentThread().isInterrupted() before entering any Jsch calls, it works. But, I doesn't guarantee if my Thread is interrupted in Jsch calls.
Here is jstack output of hang at rm() call:
"pool-1-thread-1" prio=10 tid=0x00007fa96c017000 nid=0x7226 in Object.wait() [0x00007fa9a09a7000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000ed122918> (a com.jcraft.jsch.Channel$MyPipedInputStream)
at java.io.PipedInputStream.read(PipedInputStream.java:327)
- locked <0x00000000ed122918> (a com.jcraft.jsch.Channel$MyPipedInputStream)
at java.io.PipedInputStream.read(PipedInputStream.java:378)
- locked <0x00000000ed122918> (a com.jcraft.jsch.Channel$MyPipedInputStream)
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2909)
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2901)
at com.jcraft.jsch.ChannelSftp.glob_remote(ChannelSftp.java:2713)
at com.jcraft.jsch.ChannelSftp.rm(ChannelSftp.java:1965)
at com.ubtools.ubutils.ssh.UBShellSftp.rm(UBShellSftp.java:78)
.....
Here is the first exception from the log:
1000 |4:
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2235)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2242)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:928)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:888)
at com.ubtools.ubutils.ssh.UBShellSftp.get(UBShellSftp.java:45)
at com.ubtools.ubguard.ArchivelogTransferTask.transferArchivelogs(ArchivelogTransferTask.java:471)
at com.ubtools.ubguard.ArchivelogTransferTask.runTask(ArchivelogTransferTask.java:551)
at com.ubtools.ubguard.ArchivelogTransferTask.run(ArchivelogTransferTask.java:584)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.InterruptedIOException
at java.io.PipedInputStream.read(PipedInputStream.java:329)
at java.io.PipedInputStream.read(PipedInputStream.java:378)
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2909)
at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2935)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2216)
... 14 more
As I can understand, java.lang.InterruptedException() is caught somewhere in the code which clears interrupt status. This causes may application to lose interrupt and continue, then hang in rm() call.
Here are the next exceptions from the log:
1000 |4:
at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:1056)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:985)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:888)
at com.ubtools.ubutils.ssh.UBShellSftp.get(UBShellSftp.java:45)
at com.ubtools.ubguard.ArchivelogTransferTask.transferArchivelogs(ArchivelogTransferTask.java:471)
at com.ubtools.ubguard.ArchivelogTransferTask.runTask(ArchivelogTransferTask.java:551)
at com.ubtools.ubguard.ArchivelogTransferTask.run(ArchivelogTransferTask.java:584)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
|2017-11-07 22:26:15.796 |-2147483606
1000 |4: /tmp/ubGuard/dbstby1/*
at com.ubtools.ubutils.ssh.UBShellSftp.rm(UBShellSftp.java:81)
at com.ubtools.ubguard.ArchivelogTransferTask.copyArchivelogAsmToTmp(ArchivelogTransferTask.java:357)
at com.ubtools.ubguard.ArchivelogTransferTask.transferArchivelogs(ArchivelogTransferTask.java:464)
at com.ubtools.ubguard.ArchivelogTransferTask.runTask(ArchivelogTransferTask.java:551)
at com.ubtools.ubguard.ArchivelogTransferTask.run(ArchivelogTransferTask.java:584)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
|2017-11-07 22:26:15.975 |-2147483606
1000 |4:
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2227)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2242)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:928)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:888)
at com.ubtools.ubutils.ssh.UBShellSftp.get(UBShellSftp.java:45)
at com.ubtools.ubguard.ArchivelogTransferTask.transferArchivelogs(ArchivelogTransferTask.java:471)
at com.ubtools.ubguard.ArchivelogTransferTask.runTask(ArchivelogTransferTask.java:551)
at com.ubtools.ubguard.ArchivelogTransferTask.run(ArchivelogTransferTask.java:584)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
We have a similar problem. One of our customer reports that copying data with JSch 0.1.52 to a SFTP location randomly hangs and can't be interrupted:
There are two catch blocks that consume java.lang.InterruptedException in com.jcraft.jsch.Session.write(Packet, Channel, int) (grepcode.com).
will there be a fix/workaround for this important problem ?
Having the same issue with
com.jcraft.jsch.Session::connect, which ignores java.lang.InterruptedException and thus clearing the thread's interrupted flag. If instead set the flag back :
Thread.currentThread().interrupt(); // set interrupt flag
in the catch, the problem could be resolved.