Siege segfaulting

Mikko Työläjärvi mbsd at pacbell.net
Sun Apr 18 14:00:22 PDT 2004


On Sun, 18 Apr 2004, Ivan Voras wrote:

> I was asked to send details about a problem I found with siege on
> 5.2-current. Here is my original post from current at freebsd.org:
>
> There are problems (segfault) running siege (web benchmark program) on a
> recent FreeBSD 5.2-current (a few days ago). When I switch it to libc_r
> via libmap.conf, everything works ok. Since the software is ported to a
> large number of platforms and works ok, it's likely a libpthread bug

Or not.  Last time I tried to use siege, I ran into so many bugs that
I gave up on it.

> Siege uses threading to make simultaneous HTTP requests. I tried with a
> recent release (2.59) and beta (2.60) version if siege, with same behaviour.
>
> This does not happend with small number of threads (2-3), but if I
> specify a larger number (usually 8+), it crashes in the middle of work.

Looks like a porting error; siege is calling gethostbyname(), which is
non-reentrant.

Try this patch (put it into siege/files/patch-src::sock.c) and rebuild
the port:

% cd /usr/ports/benchmarks/siege && cat files/patch-src::sock.c
--- src/sock.c.orig	Sun Apr 18 13:34:08 2004
+++ src/sock.c	Sun Apr 18 13:34:43 2004
@@ -132,7 +132,7 @@
   if((gethostbyname_r( hn, &hent, hbf, sizeof(hbf), &hp, &herrno ) < 0)){
     hp = NULL;
   }
-#elif defined(sun)
+#elif defined(sun) || defined(__FreeBSD__)
 # ifdef HAVE_GETIPNODEBYNAME
   hp = getipnodebyname( hn, AF_INET, 0, &herrno );
 # else /* default use gethostbyname_r*/
@@ -155,7 +155,7 @@
   if( hp == NULL ){ return -1; }
   memset((void*) &cli, 0, sizeof( cli ));
   memcpy( &cli.sin_addr, hp->h_addr, hp->h_length );
-#if defined(sun)
+#if defined(sun) || defined(__FreeBSD__)
 # ifdef  HAVE_FREEHOSTENT
   freehostent(hp);
 # endif/*HAVE_FREEHOSTENT*/
@@ -257,6 +257,7 @@
   return( C->sock );
 }

+#if 0 /* unused */
 /**
  * local function
  * returns hostent based on OS specifics
@@ -313,6 +314,7 @@
   xfree( buf );
   return( hp );
 }
+#endif

 /**
  * makes the socket non-blocking,

I ran some quick tests on a less than a month old -CURRENT, and with
this patch siege runs to completion.  Without the patch, siege crashes
within half a minute.

   $.02,
   /Mikko


More information about the freebsd-threads mailing list