You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/09/22 15:18:38 UTC

[GitHub] [commons-vfs] zhwq1216 opened a new pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

zhwq1216 opened a new pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215


   Try to copy a file from local to sftp server, if the sftp target directory can't write by the sftp user, it throw a exception as below.
   
   ```
   Caused by: org.apache.commons.vfs2.FileSystemException: Could not write to "sftp://sftpuser:***@localhost/noperms/test.dat.tmp".
   	at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1270)
   	at org.apache.commons.vfs2.provider.DefaultFileContent.buildOutputStream(DefaultFileContent.java:540)
   	at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:406)
   	at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:394)
   	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:815)
   	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:833)
   	at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:37)
   	at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:297)
   	... 29 common frames omitted
   Caused by: com.jcraft.jsch.SftpException: Permission denied
   	at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
   	at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:768)
   	at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:709)
   	at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:706)
   	at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetOutputStream(SftpFileObject.java:483)
   	at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1266)
   	... 36 common frames omitted
   ```
   the exception is from the version 2.5.0.
   
   the retry times is more than 20, then the exception stack as below:
   ```
   Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "sftp://sftpuser:***@localhost/".
   	at org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getChannel(SftpFileSystem.java:159)
   	at org.apache.commons.vfs2.provider.sftp.SftpFileObject.statSelf(SftpFileObject.java:106)
   	at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetType(SftpFileObject.java:76)
   	at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1368)
   	... 30 common frames omitted
   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:133)
   	... 33 common frames omitted
   ```
   
   Although the sftp directory permission problem is fixed, the file cannot be copied to the sftp target directory, and the error stack still `channel is not opened`.
   
   The PR  try to catch  the exception on `SftpFileObject.doGetOutputStream`,  if there is a exception on the method `channel.put`, use the `getAbstractFileSystem().putChannel(channel)` to return the channel to the pool.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] zhwq1216 commented on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
zhwq1216 commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-927231575


   > You'll need some kind of unit test to show that this actually fixes something. See https://github.com/apache/commons-vfs/tree/master/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp
   
   I tried to add some unit tests, but AbstractSftpProviderTestCase cannot simulate the situation where the directory does not have write permissions, so it cannot verify that `channel.put` throws an exception. I checked `org.apache.commons.vfs2.provider.ftp.FtpFileObject#doGetOutputStream`, there is a code block similar to the method of catching the exception


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory commented on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-932337491


   @zhwq1216 
   I'll try to get to this over the weekend. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory edited a comment on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
garydgregory edited a comment on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-925149791


   You'll need some kind of unit test to show that this actually fixes something.  See https://github.com/apache/commons-vfs/tree/master/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory commented on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-925149791


   You'll need some kind of unit test to show that this actually fixes something. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] zhwq1216 commented on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
zhwq1216 commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-927591393


   > Have you tried setting the directory attribu
   
   Thanks for your suggestion. I add a unit test, could you review it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory commented on pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-927289128


   Have you tried setting the directory attributes through https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory commented on pull request #215: SFTP channel isn't returned to the pool when SftpFileObject.doGetOutputStream throws an exception.

Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215#issuecomment-980183831


   TY @zhwq1216 !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [commons-vfs] garydgregory merged pull request #215: fix the sftp channel don't return to the pool when exception on SftpFileObject.doGetOutputStream

Posted by GitBox <gi...@apache.org>.
garydgregory merged pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org