lessfs is leaking sockets if listening port is already in use

14 views
Skip to first unread message

hajo

unread,
Nov 19, 2013, 10:11:48 AM11/19/13
to les...@googlegroups.com
Hello,
I have configurations running two instances of lessfs on the same server.
In this case, if the listening port (normally 100) is not configured to a different number in the lessfs config files, the second instance started is trying to bind the same port and fails, but the socket created is not freed. This is retried every second, so finally the process runs out of sockets.
Best Regards,
Hajo

Fixed this in lib_net.c of lessfs-1.5.13:

*** lib_net.c   Fri Nov 15 13:44:09 2013
--- lib_net.c.orig      Tue Nov 19 16:02:06 2013
***************
*** 326,335 ****
      if (bind
          (mastersock, (struct sockaddr *) &socketaddr,
           sizeof(socketaddr)) < 0) {
- #if 1
-         LFATAL("couldn't bind socket to port %s", port);
-         close(mastersock);
- #endif
          return -1;
      }

--- 326,331 ----

In addition to that, there are two locations where an invalid socket is tried to be closed, so this generates an error, too. In the error situation, msocket is -1, so closing it will not work:

*** lessfs.c    Fri Nov 15 14:02:06 2013
--- lessfs.c.orig       Mon Feb 25 09:30:40 2013
***************
*** 1540,1548 ****
          if (msocket != -1)
              break;
          sleep(1);
- #if 0
          close(msocket);
- #endif
      }

      client_len = sizeof(client_address);
--- 1540,1546 ----

*** lib_repl.c  Fri Nov 15 14:02:39 2013
--- lib_repl.c.orig     Tue Nov 19 15:56:27 2013
***************
*** 608,616 ****
              break;
          LINFO("replication_worker : serverinit failed: retry");
          sleep(1);
- #if 0
          close(msocket);
- #endif
      }
      message = s_zmalloc(BLKSIZE * 2);   // Enough space to hold the message and the kitchen sink
      client_len = sizeof(client_address);
--- 608,614 ----

Reply all
Reply to author
Forward
0 new messages