You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-dev@incubator.apache.org by Rana Bhattacharyya <ra...@yahoo.com> on 2006/05/05 13:39:01 UTC

Re: Bug, Server locks up because of firewall issues

Hi,

    I am sorry for the late reply. I think you have a
valid point. The problem you are mentioning is that
the client processing will not start if it begins
during the timerTask as it is synchronized over the
connection list. We shall modify the timerTask to use
a clone of the connection list.

Thanks for pointing this.

- Rana Bhattacharyya


--- OZAKI Ittetsu <al...@tesltd.co.jp> wrote:

> 
> Hi,
> 
> I was encountering this problem.
> Thank you very much for fixing the code.
> 
> BTW, part of the reason for this problem is
> synchronized
> conList, accessed by timerTask() and
> newConnection().
> 
> When servSoc.accept() blocks, conList is kept locked
> by 
> timerTask() until servSoc.accept() returns. 
> So newConnection() has to wait, because
> conList.add() 
> is synchronized.
> 
> I guess it's better that timerTask() iterates over 
> "clone" of conList, than synchronizes on it. 
> How do you think?
> 
> Thanks,
> OZAKI Ittetsu
> 
> 
> On Mon, 24 Apr 2006 03:14:06 -0700 (PDT)
> Rana Bhattacharyya <ra...@yahoo.com> wrote:
> 
> > Hi,
> > 
> >   Thank you very much for replying. You are
> absolutely
> > right. I shall add one data connection
> configuration
> > parameter to set the server socket timeout.
> Basically
> > I shall set the SO_TIMEOUT.
> > 
> > FtpDataConnection is not shared in multiple
> > connections. Each ftp session has a
> FtpDataConnection
> > instance. So other client can open data connection
> > when  server is waiting for one client.
> > 
> > These are synchronized because, the FTP session
> > cleaner removes idle connections at specified
> interval
> > and this timer thread can mess-up if these methods
> are
> > not synchronized.
> > 
> > Thanks,
> > Rana Bhattacharyya
> > 
> > 
> > --- Jens Viebig <jv...@como.com> wrote:
> > 
> > > I did some more testing and the two functions i
> > > pointed out do no harm and 
> > > return immediately.
> > > The function that is causing the hang is in
> > > FtpDataConnection as you pointed 
> > > out:
> > > 
> > >     public synchronized Socket getDataSocket() {
> > >     ...
> > >                 m_dataSoc = m_servSoc.accept();
> > >     ...
> > >     }
> > > 
> > > Yes i would definetely add a timeout for
> m_servSoc.
> > > 
> > > Without a timeout this function waits forever,
> when
> > > the data connection is 
> > > not established. This is not good and there are
> > > several reasons why this 
> > > coud happen (Server side-firewalls, client-side
> > > firewalls, broken ftp 
> > > clients,broken network connections...).
> > > 
> > > Does this function have to be synchronized ?
> Even
> > > with a timeout for the 
> > > server socket, while the server waits for the
> > > incoming data connection, no 
> > > other client can connect to the server.
> > > 
> > > ----- Original Message ----- 
> > > From: "Rana Bhattacharyya" <ra...@yahoo.com>
> > > To: <ft...@incubator.apache.org>
> > > Sent: Monday, April 24, 2006 7:17 AM
> > > Subject: Re: Bug, Server locks up because of
> > > firewall issues
> > > 
> > > 
> > > > Hi,
> > > >
> > > >   new RequestHandler() handles the new
> connection.
> > > It
> > > > does not handle the passive mode data
> transfer.
> > > > FtpDataConnection class handles all data
> > > connections
> > > > (both active and passive). So you are
> suggesting
> > > to
> > > > close the passive server socket if there is no
> > > client
> > > > connections within a speified time to prevent
> > > server
> > > > lock out. Please write your comments.
> > > >
> > > > Thanks,
> > > > Rana Bhattacharyya
> > > >
> > > >
> > > > --- Jens Viebig <jv...@como.com> wrote:
> > > >
> > > >> Hi List,
> > > >> I found a situation where the ftp server
> locks up
> > > >> and no new connections can be made.
> > > >> ftpserver runs behind a firewall with open
> port
> > > 21
> > > >> and runs fine with clients working in active
> > > mode.
> > > >> When a client tries to connect in passive
> mode,
> > > the
> > > >> data connection is blocked by the firewall.
> This
> > > is
> > > >> the point where the server locks up. It seems
> > > that
> > > >> the server is waiting for the incoming data
> > > >> connection that is never established because
> of
> > > the
> > > >> firewall.
> > > >>
> > > >> The main thread executes two functions after
> > > >> accepting the client socket connection
> > > >>
> > > >>  IConnection connection = new
> > > >> RequestHandler(m_ftpConfig, soc);
> > > >>  conManager.newConnection(connection);
> > > >>
> > > >> it seems that one of the functions causes the
> > > >> hangup. In my understanding of server
> > > architecture
> > > >> the thread handling the client connection
> should
> > > be
> > > >> forked immediately after the accept() of the
> > > socket
> > > >> or the functions should have a very short
> > > timeout,
> > > >> because no new connections can be established
> > > while
> > > >> these functions are executed.
> > > >>
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > > >
> __________________________________________________
> > > > Do You Yahoo!?
> > > > Tired of spam?  Yahoo! Mail has the best spam
> > > protection around
> > > > http://mail.yahoo.com
> > > >
> > > > 
> > > 
> > > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> > http://mail.yahoo.com 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Bug, Server locks up because of firewall issues

Posted by OZAKI Ittetsu <al...@tesltd.co.jp>.
Hi,

It seems my attachement file was lost somewhere.
This time I paste the patch in body. Sorry.


Index: src/java/org/apache/ftpserver/ConnectionManagerImpl.java
===================================================================
--- src/java/org/apache/ftpserver/ConnectionManagerImpl.java	(revision 407453)
+++ src/java/org/apache/ftpserver/ConnectionManagerImpl.java	(working copy)
@@ -230,9 +230,9 @@
         if(conList == null) {
             return;
         }
+        conList = new Vector(conList);
         
         // get inactive client connection list 
-        synchronized(conList) {
             for( int i = conList.size(); --i>=0; ) {
                 IConnection con = (IConnection)conList.get(i);
                 if(con == null) {
@@ -263,7 +263,6 @@
                     }
                 }
             }
-        }
 
         // close idle client connections
         for( Iterator conIt=inactiveCons.iterator(); conIt.hasNext(); ) {


Thanks,
OZAKI Ittetsu





Re: Bug, Server locks up because of firewall issues

Posted by OZAKI Ittetsu <al...@tesltd.co.jp>.
Rana,

A patch attached which modifies the timerTask.

> We shall modify the timerTask to use
> a clone of the connection list.

Is "We" mean Rana and the other committers, 
or Rana and me?
Sorry, I am bad at english..

Thanks,
OZAKI Ittetsu




On Fri, 5 May 2006 06:39:01 -0700 (PDT)
Rana Bhattacharyya <ra...@yahoo.com> wrote:

> Hi,
> 
>     I am sorry for the late reply. I think you have a
> valid point. The problem you are mentioning is that
> the client processing will not start if it begins
> during the timerTask as it is synchronized over the
> connection list. We shall modify the timerTask to use
> a clone of the connection list.
> 
> Thanks for pointing this.
> 
> - Rana Bhattacharyya
> 
> 
> --- OZAKI Ittetsu <al...@tesltd.co.jp> wrote:
> 
> > 
> > Hi,
> > 
> > I was encountering this problem.
> > Thank you very much for fixing the code.
> > 
> > BTW, part of the reason for this problem is
> > synchronized
> > conList, accessed by timerTask() and
> > newConnection().
> > 
> > When servSoc.accept() blocks, conList is kept locked
> > by 
> > timerTask() until servSoc.accept() returns. 
> > So newConnection() has to wait, because
> > conList.add() 
> > is synchronized.
> > 
> > I guess it's better that timerTask() iterates over 
> > "clone" of conList, than synchronizes on it. 
> > How do you think?
> > 
> > Thanks,
> > OZAKI Ittetsu
> > 
> > 
> > On Mon, 24 Apr 2006 03:14:06 -0700 (PDT)
> > Rana Bhattacharyya <ra...@yahoo.com> wrote:
> > 
> > > Hi,
> > > 
> > >   Thank you very much for replying. You are
> > absolutely
> > > right. I shall add one data connection
> > configuration
> > > parameter to set the server socket timeout.
> > Basically
> > > I shall set the SO_TIMEOUT.
> > > 
> > > FtpDataConnection is not shared in multiple
> > > connections. Each ftp session has a
> > FtpDataConnection
> > > instance. So other client can open data connection
> > > when  server is waiting for one client.
> > > 
> > > These are synchronized because, the FTP session
> > > cleaner removes idle connections at specified
> > interval
> > > and this timer thread can mess-up if these methods
> > are
> > > not synchronized.
> > > 
> > > Thanks,
> > > Rana Bhattacharyya
> > > 
> > > 
> > > --- Jens Viebig <jv...@como.com> wrote:
> > > 
> > > > I did some more testing and the two functions i
> > > > pointed out do no harm and 
> > > > return immediately.
> > > > The function that is causing the hang is in
> > > > FtpDataConnection as you pointed 
> > > > out:
> > > > 
> > > >     public synchronized Socket getDataSocket() {
> > > >     ...
> > > >                 m_dataSoc = m_servSoc.accept();
> > > >     ...
> > > >     }
> > > > 
> > > > Yes i would definetely add a timeout for
> > m_servSoc.
> > > > 
> > > > Without a timeout this function waits forever,
> > when
> > > > the data connection is 
> > > > not established. This is not good and there are
> > > > several reasons why this 
> > > > coud happen (Server side-firewalls, client-side
> > > > firewalls, broken ftp 
> > > > clients,broken network connections...).
> > > > 
> > > > Does this function have to be synchronized ?
> > Even
> > > > with a timeout for the 
> > > > server socket, while the server waits for the
> > > > incoming data connection, no 
> > > > other client can connect to the server.
> > > > 
> > > > ----- Original Message ----- 
> > > > From: "Rana Bhattacharyya" <ra...@yahoo.com>
> > > > To: <ft...@incubator.apache.org>
> > > > Sent: Monday, April 24, 2006 7:17 AM
> > > > Subject: Re: Bug, Server locks up because of
> > > > firewall issues
> > > > 
> > > > 
> > > > > Hi,
> > > > >
> > > > >   new RequestHandler() handles the new
> > connection.
> > > > It
> > > > > does not handle the passive mode data
> > transfer.
> > > > > FtpDataConnection class handles all data
> > > > connections
> > > > > (both active and passive). So you are
> > suggesting
> > > > to
> > > > > close the passive server socket if there is no
> > > > client
> > > > > connections within a speified time to prevent
> > > > server
> > > > > lock out. Please write your comments.
> > > > >
> > > > > Thanks,
> > > > > Rana Bhattacharyya
> > > > >
> > > > >
> > > > > --- Jens Viebig <jv...@como.com> wrote:
> > > > >
> > > > >> Hi List,
> > > > >> I found a situation where the ftp server
> > locks up
> > > > >> and no new connections can be made.
> > > > >> ftpserver runs behind a firewall with open
> > port
> > > > 21
> > > > >> and runs fine with clients working in active
> > > > mode.
> > > > >> When a client tries to connect in passive
> > mode,
> > > > the
> > > > >> data connection is blocked by the firewall.
> > This
> > > > is
> > > > >> the point where the server locks up. It seems
> > > > that
> > > > >> the server is waiting for the incoming data
> > > > >> connection that is never established because
> > of
> > > > the
> > > > >> firewall.
> > > > >>
> > > > >> The main thread executes two functions after
> > > > >> accepting the client socket connection
> > > > >>
> > > > >>  IConnection connection = new
> > > > >> RequestHandler(m_ftpConfig, soc);
> > > > >>  conManager.newConnection(connection);
> > > > >>
> > > > >> it seems that one of the functions causes the
> > > > >> hangup. In my understanding of server
> > > > architecture
> > > > >> the thread handling the client connection
> > should
> > > > be
> > > > >> forked immediately after the accept() of the
> > > > socket
> > > > >> or the functions should have a very short
> > > > timeout,
> > > > >> because no new connections can be established
> > > > while
> > > > >> these functions are executed.
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > > >
> > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Tired of spam?  Yahoo! Mail has the best spam
> > > > protection around
> > > > > http://mail.yahoo.com
> > > > >
> > > > > 
> > > > 
> > > > 
> > > 
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam
> > protection around 
> > > http://mail.yahoo.com 
> > 
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

-- 
OZAKI Ittetsu <al...@tesltd.co.jp>