You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "wangerry (Jira)" <ji...@apache.org> on 2023/02/03 01:47:00 UTC
[jira] [Updated] (VFS-832) Sftp channel not put back in doGetInputStream
[ https://issues.apache.org/jira/browse/VFS-832?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
wangerry updated VFS-832:
-------------------------
Summary: Sftp channel not put back in doGetInputStream (was: Sftp channel not put back in doGetInputUpstream )
> Sftp channel not put back in doGetInputStream
> ---------------------------------------------
>
> Key: VFS-832
> URL: https://issues.apache.org/jira/browse/VFS-832
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.9.0
> Reporter: wangerry
> Priority: Major
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> *since VFS-210 added this in SftpFileObject.java:*
>
> {code:java}
> InputStream is;
> try
> {
> // VFS-210: sftp allows to gather an input stream even from a directory and will
> // fail on first read. So we need to check the type anyway
> if (!getType().hasContent())
> {
> throw new FileSystemException("vfs.provider/read-not-file.error", getName());
> }
> is = channel.get(relPath);
> }
> catch (SftpException e)
> {
> if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
> {
> throw new FileNotFoundException(getName());
> }
> throw new FileSystemException(e);
> }{code}
> when throw an exception(such as file not exists or get input stream from a directory), the channel is not called with putChannel() and not be closed. when this happen several times (normally 10 times due to sshd default MaxSession is 10), getChannel() will always throws exception(Channel is not opened), because server will not response the open request.
>
> *It can be reproduced in this way:*
>
> {code:java}
> //Setup our SFTP configuration
> FileSystemOptions opts = new FileSystemOptions();
> SftpFileSystemConfigBuilder instance = SftpFileSystemConfigBuilder.getInstance();
> instance.setStrictHostKeyChecking(opts, "no");
> instance.setUserDirIsRoot(opts, true);
> instance.setConnectTimeout(opts, Duration.ofSeconds(30));
> instance.setSessionTimeout(opts, Duration.ofSeconds(30));
> instance.setDisableDetectExecChannel(opts, true);
> for (int i = 0; i < 15; i++) {
> try {
> try (FileObject fileObject = VFS.getManager().resolveFile("sftp://foo@example.com/path_not_exists.txt", opts)) {
> try (InputStream inputStream = fileObject.getContent().getInputStream()) {
> // do something
> }
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> } {code}
> first 10 times will be "Could not read from "xxx" because it is not a file."
>
> then will be
>
> {code:java}
> Caused by: com.jcraft.jsch.JSchException: channel is not opened.
> at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:768)
> at com.jcraft.jsch.Channel.connect(Channel.java:151)
> at org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getChannel(SftpFileSystem.java:213)
> ... 6 more {code}
>
> I will commit a pr to fix this
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)