You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jared Graber <jg...@zedak.com> on 2006/03/28 19:48:35 UTC

RE: [vfs]sFTP Imaginary Directory Type (FOUND BUG)

Well, I found the problem with the 2 libraries (VFS and JSch 0.1.25 which is
the latest) by adding logging to JSch (which to my surprise had NONE!) and
running multiple tests.

If in the middle of a file transfer the sftp server goes down, JSch chokes.
>From then on, a null pointer exception occurs in the stat method of the
ChannelSftp.  Unfortunately the method catches ANY exception and just throws
a new SftpException (or casts the exception if it was already a
SftpException) with no logging of what really happened.  

So the connection is busted, but the library isn't letting anyone know what
happened.

The SftpFileObject of VFS catches the exception (there is a TODO in there)
and sets the attributes of the file object to null.  This will cause the
type of the file to be imaginary.

Because the JSch library didn't handle the exception properly, this problem
will continue to occur until the program is restarted without putting in
safeguards.

Without changing VFS or JSch code, the solution I found was to get the
FileSystem object from the FileObject, cast it to an AbstractFileSystem (I
hate doing something like this) and calling the close() method on it.

If someone has a better solution (other than fixing JSch or making a change
to the SftpFileObject so that it closes the file system object when the
SftpException occurs), please let me know.

I'm a little confused on the reasoning behind the Imaginary File Type.  It
seems to me that it is just a catch all for anything that can go wrong.  If
that's the case, I would think an exception would make more sense.  It would
also give you an idea of what went wrong.

I hope none of the other supported file systems have the same type of
problem.

-Jared

-----Original Message-----
From: Jared Graber [mailto:jgraber@zedak.com] 
Sent: Friday, March 17, 2006 2:30 PM
To: Jakarta Commons Users List
Subject: [vfs]sFTP Imaginary Directory Type

Hi,

 

I've been using VFS (with the JSch library) to connect to an SFTP server.
Today we encountered an interesting problem that unfortunately I haven't
been able to duplicate yet.

 

One of our requirements is to get the name of all the files in a folder w/ a
specific extension.

 

This part of the app is part of a daemon thread and is called pretty often.

Here is the code:

 

                        FileSystemManager fileSystemManager = null;

                        FileObject directory = null;

                        TagFileListing tags;

                        try {

                                    fileSystemManager = VFS.getManager();

                                    directory =
fileSystemManager.resolveFile(this.getFileLocationURI());

                                    if (LOG.isDebugEnabled())
LOG.debug("File location: '" + this.getFileLocationURI() + "'");

                                    FileSelector tagFileSelector = new
FileExtensionSelector(".tag");

                                    if (LOG.isDebugEnabled())
LOG.debug("Directory Path: " + directory.getName().getPath());

                                    if (LOG.isDebugEnabled())
LOG.debug("Directory Type: " + directory.getType().getName());

 

                                    FileObject [] tagFiles =
directory.findFiles(tagFileSelector);

                                    tags = new TagFileListing();

                                    if (tagFiles != null) {

                                                if (LOG.isDebugEnabled())
LOG.debug("Tag files found:\t" + tagFiles.length);

                                                for (int i = 0; i <
tagFiles.length; i++) {

                                                            FileObject
tagFile = tagFiles[i];

                                                            String tagName =
tagFile.getName().getBaseName();

                                                            if
(LOG.isDebugEnabled()) LOG.debug("Found tag file: '" + tagName + "'");

 
tags.addTagFile(tagName);

                                                }

                                    }

                                    else {

                                                if (LOG.isDebugEnabled())
LOG.debug("No tag files found");

                                    }

                                    return tags;

                        } finally {

                                    if (directory != null)
directory.close();

                                    if (fileSystemManager != null)
fileSystemManager.getFilesCache().close();

                        }

 

 

I'm thinking that the problem is that the type for the FileObject directory
is FileType.Imaginary or I'm not using the provided caching correctly. 

No FileObjects are (incorrectly) returned by
directory.findFile(tagFileSelector)

 

If we restart the application, the type of 'directory' is FOLDER (which is
expected) and a correct set of FileObjects is returned by the findFiles
method.

The value of this.getFileLocationURI()  did not change when we restarted the
app (it originates from configuration parameters).

 

Any ideas as to what went wrong?

 

-Jared



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: [vfs]sFTP Imaginary Directory Type (FOUND BUG)

Posted by Jared Graber <jg...@zedak.com>.
I will contact the JSch developer to get his input on the issue.

I didn't make a change to VFS to fix this problem.  I made a less than
desirable change to the code that uses VFS (checking to see if the file is
imaginary and closing and restarting the process if it is imaginary).  I
haven't put too much thought into how I would change VFS to account for
problem, but maybe something can be done in the SftpFileObject when the
SftpException is thrown.  Worst case scenario, it can throw an exception to
indicate something went wrong.

-Jared


-----Original Message-----
From: Mario Ivankovits [mailto:mario@ops.co.at] 
Sent: Wednesday, March 29, 2006 1:32 AM
To: Jakarta Commons Users List
Subject: Re: [vfs]sFTP Imaginary Directory Type (FOUND BUG)

Hi!
> So the connection is busted, but the library isn't letting anyone know
what
> happened.
>   
The best will be to talk to the jsch developer. I am pretty sure he will
fix it if its a bug.
> Without changing VFS or JSch code,
Whats your VFS change to fix this?
As a quick-fix in SftpFileSystem in putChannel I check if the channel is
still connected/alive. And retry the stat if an exception other than
NO_SUCH_FILE occurs.

> I'm a little confused on the reasoning behind the Imaginary File Type.  It
> seems to me that it is just a catch all for anything that can go wrong.
No. The imaginary file type is used to state that a file is no existent.
Only for jsch it looks like - due to the problem described in the todo -
it is a catch all.

Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [vfs]sFTP Imaginary Directory Type (FOUND BUG)

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> So the connection is busted, but the library isn't letting anyone know what
> happened.
>   
The best will be to talk to the jsch developer. I am pretty sure he will
fix it if its a bug.
> Without changing VFS or JSch code,
Whats your VFS change to fix this?
As a quick-fix in SftpFileSystem in putChannel I check if the channel is
still connected/alive. And retry the stat if an exception other than
NO_SUCH_FILE occurs.

> I'm a little confused on the reasoning behind the Imaginary File Type.  It
> seems to me that it is just a catch all for anything that can go wrong.
No. The imaginary file type is used to state that a file is no existent.
Only for jsch it looks like - due to the problem described in the todo -
it is a catch all.

Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org