Skip to content

inputstream is closed error connecting to a slow server #858

@gtoison

Description

@gtoison

Hello,
I'm using jsch 2.27.2 to download files from an SFTP server.
Today the server seems a lot slower than usual and I'm getting this error:

Caused by: java.io.IOException: inputstream is closed
	at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2872)
	at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2898)
	at com.jcraft.jsch.ChannelSftp.start(ChannelSftp.java:254)

It seems to me that header() attemps to read 9 bytes from the input stream, but does not get anything because the (super slow) server has not started replying.

I tried adding a delay Thread.sleep(Duration.ofMinutes(1)); before that line:

header = header(buf, header);

The workaround seems to work albeit obviously slowing things down.

Would you agree that this seems like a bug?
IMO the fill() method (or its caller) should somehow loop when it does not read enough data.

The commented out code seems to indicate that this was the intent at some point:

private int fill(byte[] buf, int s, int len) throws IOException {
int i = 0;
int foo = s;
while (len > 0) {
i = io_in.read(buf, s, len);
if (i <= 0) {
throw new IOException("inputstream is closed");
// return (s-foo)==0 ? i : s-foo;
}
s += i;
len -= i;
}
return s - foo;
}
private void skip(long foo) throws IOException {
while (foo > 0) {
long bar = io_in.skip(foo);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions