[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mapserver-dev
Subject:    [mapserver-dev] Fwd: mapserver deadlock on signal
From:       Lauri <lauri.nomme () gmail ! com>
Date:       2011-11-08 13:35:51
Message-ID: CALadjcNMD+ws-FY-xUycS0nyziEviAE2pyCFjnnJRVfFOWZjCQ () mail ! gmail ! com
[Download RAW message or body]

Hi

There is a bug in how mapserver handles USR1 and TERM signals when
used in fastcgi mode.
msCleanupOnSignal calls msCleanup, which calls gdFontCacheShutdown
which tries to acquire a mutex that can already be locked, deadlocking
the process.

A sample stack trace showing the symptoms:
Process 12533 attached - interrupt to quit
futex(0x7ffdcb1b7d80, FUTEX_WAIT_PRIVATE, 2, NULL

(gdb) bt
#0 =A00x00007fdf9ec99be4 in __lll_lock_wait () from /lib/libpthread.so.0
#1 =A00x00007fdf9ec950e9 in _L_lock_953 () from /lib/libpthread.so.0
#2 =A00x00007fdf9ec94f0b in pthread_mutex_lock () from /lib/libpthread.so.0
#3 =A00x00007fdfa19edf1a in gdFontCacheShutdown () from /usr/lib/libgd.so.2
#4 =A00x000000000047e890 in msCleanup ()
#5 =A00x000000000044b4d0 in msCleanupOnSignal ()
#6 =A0<signal handler called>
#7 =A00x00007fdfa154b538 in TT_RunIns () from /usr/lib/libfreetype.so.6
#8 =A00x00007fdfa1546073 in ?? () from /usr/lib/libfreetype.so.6
#9 =A00x00007fdfa154edc1 in ?? () from /usr/lib/libfreetype.so.6
#10 0x00007fdfa154f47d in ?? () from /usr/lib/libfreetype.so.6
#11 0x00007fdfa153b4aa in FT_Load_Glyph () from /usr/lib/libfreetype.so.6
#12 0x00007fdfa19eccb3 in gdImageStringFTEx () from /usr/lib/libgd.so.2
#13 0x00007fdfa19ed89b in gdImageStringFT () from /usr/lib/libgd.so.2
#14 0x00000000004cd151 in msDrawTextLineGD ()
#15 0x000000000057de7e in msDrawTextLine ()
#16 0x00000000004b8286 in msDrawLabelCache ()
#17 0x00000000004ad595 in msDrawMap ()
#18 0x00000000005a6aea in msWMSGetMap ()
#19 0x00000000005aa52d in msWMSDispatch ()
#20 0x000000000050ce91 in msOWSDispatch ()
#21 0x000000000044b8b8 in main ()

Patch for this problem is attached.

Lauri N=F5mme

["02_signalhandling.dpatch" (application/octet-stream)]

#! /bin/sh /usr/share/dpatch/dpatch-run
## 02_signalhandling.dpatch by Lauri Nomme <lauri.nomme@gmail.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad mapserver-5.6.5~/mapserv.c mapserver-5.6.5/mapserv.c
--- mapserver-5.6.5~/mapserv.c	2011-11-08 14:41:26.000000000 +0200
+++ mapserver-5.6.5/mapserv.c	2011-11-08 14:41:35.000000000 +0200
@@ -1076,19 +1076,15 @@
 }
 
 
+static int exitSignal;
+
 /************************************************************************/
 /*                      FastCGI cleanup functions.                      */
 /************************************************************************/
 #ifndef WIN32
 void msCleanupOnSignal( int nInData )
 {
-  /* For some reason, the fastcgi message code does not seem to work */
-  /* from within the signal handler on Unix.  So we force output through */
-  /* normal stdio functions. */
-  msIO_installHandlers( NULL, NULL, NULL );
-  msIO_fprintf( stderr, "In msCleanupOnSignal.\n" );
-  msCleanup();
-  exit( 0 );
+  exitSignal = 1;
 }
 #endif
 
@@ -1109,6 +1105,7 @@
 }
 #endif
 
+
 /************************************************************************/
 /*                                main()                                */
 /************************************************************************/
@@ -1121,6 +1118,7 @@
   struct mstimeval execstarttime, execendtime;
   struct mstimeval requeststarttime, requestendtime;
 
+  exitSignal = 0;
   msSetup();
 
   /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
@@ -1199,7 +1197,7 @@
 
   /* In FastCGI case we loop accepting multiple requests.  In normal CGI */
   /* use we only accept and process one request.  */
-  while( FCGI_Accept() >= 0 ) {
+  while( !exitSignal && FCGI_Accept() >= 0 ) {
 #endif /* def USE_FASTCGI */
 
     /* -------------------------------------------------------------------- */


_______________________________________________
mapserver-dev mailing list
mapserver-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic