FTP Server busy waiting when file descriptors are exhausted

Thomas Rauscher trauscher at loytec.com
Tue Apr 4 11:35:51 UTC 2006


> -----Original Message-----
> From: Chris Johns [mailto:chrisj at rtems.org] 
> Sent: Tuesday, March 28, 2006 12:40 PM
> To: Thomas Rauscher
> Cc: rtems-users
> Subject: Re: FTP Server busy waiting when file descriptors 
> are exhausted
> 
> Thomas Rauscher wrote:
> > 
> > You are right, a well designed application should not run into this
> > situation.
> > 
> 
> Ok.
> 
> > However, in my opinion the FTP server should handle this case more
> > gracefully and not hang up exhausting the entire CPU time.
> 
> Sure causing a lock up is not nice.
> 
> > Currently, the
> > problem that all fds are used triggers another problem that all
lower
> > priority threads are preempted by a not very productive thread.
> 
> Is this the case for just a single client connection ?
> 
> > 
> > This is what I'm trying to address with my two proposed solution
> > sketches.
> > 
> 
> Ok.
> 
> > 1) Add a sleep() in the FTP server (less intrusive, but doesn't fix
the
> > problem)
> 
> It cannot fix a problem else where in the code but it would resolve
the 
> loading issue which may let other code run and recover.
> 
> > 2) Close control socket and open again. However, what should happens
if
> > the control socket cannot be reopened? This would be even worse.
AFAIK, there is
> > no flush function for listening sockets.
> 
> By control socket do you mean the listen socket ?
> 
> This is not a great solution.
> 
> I am curious what the networking stack is suppose to do with a 
> connection that does not have an available fd. Should the 
> connection be 
> dropped ? Does anyone know what other operating system do ?
> 

Hi,

there has been little discussion so far. I still cannot see a clean way 
to remove pending connections in the listen socket (besides closing it).

The following patch releases the CPU in case of connection errors
so that the CPU load does not go to 100% in case of fd shortage.

Feel free to apply it to the official RTEMS branch. The diff is against
HEAD.

*** ftpd.c.orig	Tue Apr  4 13:21:52 2006
--- ftpd.c	Tue Apr  4 13:22:14 2006
***************
*** 1921,1932 ****
    else while (1)
    {
      int ss;
      addrLen = sizeof(addr);
      ss = accept(s, (struct sockaddr *)&addr, &addrLen);
!     if (0 > ss)
        syslog(LOG_ERR, "ftpd: Error accepting control connection: %s",
serr());
      else if(!set_socket_timeout(ss, ftpd_timeout))
        close_socket(ss);
      else
      {
        info = task_pool_obtain();
--- 1921,1934 ----
    else while (1)
    {
      int ss;
      addrLen = sizeof(addr);
      ss = accept(s, (struct sockaddr *)&addr, &addrLen);
!     if (0 > ss) {
        syslog(LOG_ERR, "ftpd: Error accepting control connection: %s",
serr());
+       sleep(1);
+     }
      else if(!set_socket_timeout(ss, ftpd_timeout))
        close_socket(ss);
      else
      {
        info = task_pool_obtain();

Regards,
Thomas Rauscher

--
Thomas Rauscher
LOYTEC electronics GmbH




More information about the users mailing list