commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <ima...@apache.org>
Subject [net][vfs] detection of closed ftp connections due to timeout
Date Mon, 18 Oct 2004 10:21:45 GMT
Hello!

I currently try to extend the VFS ftp implementation to allow automatic 
reconnect if the ftp connection timed out.
This already works pretty well, but it relys on the 
FTPConnectionClosedException.

The bad side is, the user who initiated this does not get a 
FTPConnectionClosedException - The exception is a SocketException 
(Broken pipe).

After discussion we found there is a firewall sitting between him and 
his ftp-server.
Now that I know firewalls which disconnects idle connections on its own, 
I bet this is what causes this "strange" exception.

FTP.isConnected() also returns true - odd thing.

Now i would like to know what we could do next.

I would like to propose to catch the SocketException and wrap a 
FTPConnectionClosedException.

In FTP.sendCommand():

try
{
        _controlOutput.write(message = __commandBuffer.toString());
        _controlOutput.flush();
}
catch (SocketException e)
{
    throw new FTPConnectionClosedException(e);
}

The question is, do a SocketException always mean "connection closed", 
for sure I dont think so, but matching the message against "broken pipe" 
is also not an option.
Maybe - in the catch block we could also query the isConnected() and 
throw the FTPConnectionClosedException() only if it is false.

For sure I send a clean patch if we find a solution.

This is what the user gets:

Caused by: java.net.SocketException: Broken pipe
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
	at
org.apache.commons.net.telnet.TelnetClient._flushOutputStream(TelnetClient.java:76)
	at
org.apache.commons.net.telnet.TelnetOutputStream.flush(TelnetOutputStream.java:136)
	at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
	at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:410)
	at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:152)
	at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
	at java.io.BufferedWriter.flush(BufferedWriter.java:236)
	at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:405)
	at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:438)
	at org.apache.commons.net.ftp.FTP.port(FTP.java:767)
	at
org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:449)
	at
org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2335)
	at
org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2309)
	at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2055)
	at
org.apache.commons.vfs.provider.ftp.FtpFileObject.doGetChildren(FtpFileObject.java:118)
	at
org.apache.commons.vfs.provider.ftp.FtpFileObject.doListChildren(FtpFileObject.java:260)
	at
org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:545)
	... 38 more


-- 
Mario


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


Mime
View raw message