Subject: | Memory corruptions and infinite locks |
Sometimes process hangs on infinte pthread_mutex_lock() with stack
backtrace:
#0 0x0010b7f2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x002986e9 in __lll_lock_wait () from /lib/libpthread.so.0
#2 0x00293dad in _L_lock_981 () from /lib/libpthread.so.0
#3 0x00293ccb in pthread_mutex_lock () from /lib/libpthread.so.0
#4 0x00f927fb in _zk_release_watches (my_perl=0x90bf008,
first_watch=0x9106cb8, final=0) at ZooKeeper.xs:280
#5 0x00f92852 in _zk_replace_watch (my_perl=0x90bf008,
handle=0x90efc60, first_watch=0x90dd8a8, old_watch=0x9106d28,
new_watch=0x9106c48) at ZooKeeper.xs:309
#6 0x00f953f1 in XS_Net__ZooKeeper_exists (my_perl=0x90bf008,
cv=0x90dfdfc) at ZooKeeper.xs:1488
#7 0x00c4e51d in Perl_pp_entersub () from
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
#8 0x00c4798f in Perl_runops_standard () from
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
#9 0x00bed20e in perl_run () from
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
The problem is in corrupted memory of mutex. Here is the fix:
--- ZooKeeper.xs 2011-11-23 16:39:49.000000000 +0400
+++ ZooKeeper.xs 2011-11-23 16:39:45.000000000 +0400
@@ -249,12 +249,13 @@
static void _zk_release_watch(pTHX_ zk_watch_t *watch, int list)
{
if (list) {
+ zk_watch_t *prev = watch->prev;
if (watch->prev) {
watch->prev->next = watch->next;
watch->prev = NULL;
}
if (watch->next) {
- watch->next->prev = watch->prev;
+ watch->next->prev = prev;
watch->next = NULL;
}
}