New Patches for cdbd / glibc 2.2.4 (fix for running out of sockets)

Oliver Jehle <[email protected]>
Newsgroups gmane.linux.failsafe
Message-ID <1019725568.917.72.camel@vorab>
Martin found a problem with the my patches... 

Problem: 
running out of sockets and leaving a lot for close_wait sockets around

Problem was that freeing memory at the wrong place... 
thanks for finding the problem !!!! attached is a complete patch against
the cdbd source directory. 

Lars can you review again and check in if it's ok 
and oss will be ready ?

Please test it and give a feedback !! 


Thanks again for Martin finding this bug.

Oliver




install:

cd ./FailSafe/cluster_admin/cmd
patch -p0 < failsafe_cdbd.diff
cd cdbd/src
make 
/etc/rc.d/init.d/fs_cluster stop
cp cdbd /usr/lib/failsafe/bin
/etc/rc.d/init.d/fs_cluster start


or do a make rpms and install the packages new with rpm -i -f
failsafe_cdbd.diff (text/x-patch, 4.6 KB)
diff -u -r cdbd.old/inc/fs2d.h cdbd/inc/fs2d.h
--- cdbd.old/inc/fs2d.h	Wed Mar 28 03:49:30 2001
+++ cdbd/inc/fs2d.h	Thu Apr 25 09:13:37 2002
@@ -375,6 +375,15 @@
 #define FS2D_POOL_MACHINE_SUBKEY_NETIF_IPADDR "ipaddr"
 #define FS2D_POOL_MACHINE_SUBKEY_NETIF_PRIORITY "priority"
 
+/* Stack Structure for xprt_close_stack */
+
+typedef struct xprt_close_stack * xprt_close_stack_ptr;
+typedef struct xprt_close_stack {
+        SVCXPRT *xprt; 
+        xprt_close_stack_ptr child;
+        xprt_close_stack_ptr parent;
+} xprt_close_stack_element;
+
 /*
  *	fs2d_global_t global data structure 
  */
@@ -388,6 +397,8 @@
 	int		service_number;
 	SVCXPRT		*xprt;
 	SVCXPRT		*xprt_table[FD_SETSIZE];
+	xprt_close_stack_ptr xprt_close_stack;
+	pthread_mutex_t      xprt_close_stack_mutex;
 	struct fs2d_process_s *process_table[FD_SETSIZE];
 
 	/* top-level database management */
@@ -930,6 +941,9 @@
 
 /* Process routines */
 extern fs2d_process_t *fs2d_locate_process(fs2d_global_t *,SVCXPRT *);
+extern void fs2d_cleanup_xprt(fs2d_global_t *);
+extern xprt_close_stack_ptr  fs2d_pop_xprt(fs2d_global_t *);
+extern void fs2d_push_xprt(fs2d_global_t *,SVCXPRT *);
 extern void fs2d_destroy_process(fs2d_global_t *,fs2d_process_t *);
 extern void fs2d_process_block(fs2d_global_t *, fs2d_process_t *, bool_t);
 extern void fs2d_process_unblock(fs2d_global_t *,fs2d_process_t *);
diff -u -r cdbd.old/src/attach.c cdbd/src/attach.c
--- cdbd.old/src/attach.c	Wed May 30 02:11:23 2001
+++ cdbd/src/attach.c	Fri Apr  5 07:55:04 2002
@@ -221,6 +221,7 @@
     int		error;
     struct sigaction sa;
     pthread_mutexattr_t mutex_attr;
+    pthread_mutexattr_t mutex_xprt_attr;
     fs2_error_t 	fserror;
     int	i;
     int	fd;
@@ -245,11 +246,14 @@
     }
 
     pthread_mutexattr_init(&mutex_attr);
+    pthread_mutexattr_init(&mutex_xprt_attr);
 
     /* in case the call ever gets added to linux... */
     /* pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_NONE); */
-
+	
+    pthread_mutex_init(&fs2d_global.xprt_close_stack_mutex,&mutex_xprt_attr);
     pthread_mutex_init(&fs2d_global.monitor,&mutex_attr);
+    pthread_mutexattr_destroy(&mutex_xprt_attr);
     pthread_mutexattr_destroy(&mutex_attr);
     fs2d_enter_monitor(&fs2d_global,NULL);
 
diff -u -r cdbd.old/src/process.c cdbd/src/process.c
--- cdbd.old/src/process.c	Thu Aug 31 03:43:24 2000
+++ cdbd/src/process.c	Thu Apr 25 09:12:53 2002
@@ -66,8 +66,9 @@
 {
 	int	fd;
 	fs2d_process_t *process;
-
 	fs2d_enter_monitor(gp,NULL);
+	if(gp->master_pid == getppid()) 
+		fs2d_cleanup_xprt(gp); 
 	fd = xprt->xp_sock;
 	if (fd >= 0 &&
 	    fd < FD_SETSIZE) {
@@ -105,6 +106,63 @@
 	return(NULL);
 }
 
+bool_t
+fs2d_has_xprt(fs2d_global_t *gp) {
+	if (gp->xprt_close_stack != NULL)
+	    return TRUE;
+	return FALSE;
+}
+
+
+xprt_close_stack_ptr 
+fs2d_pop_xprt(fs2d_global_t *gp) {
+	xprt_close_stack_ptr returnElement;
+
+        pthread_mutex_lock(&gp->xprt_close_stack_mutex);
+        returnElement = gp->xprt_close_stack;
+        if (gp->xprt_close_stack != NULL) {
+                gp->xprt_close_stack=gp->xprt_close_stack->parent;
+        }
+        pthread_mutex_unlock(&gp->xprt_close_stack_mutex);
+        return returnElement;
+}
+
+void 
+fs2d_push_xprt(fs2d_global_t *gp, SVCXPRT * in) {
+        xprt_close_stack_ptr newElement ;
+	
+	newElement = malloc(sizeof(xprt_close_stack_element));
+        newElement->xprt=in;
+       
+	 pthread_mutex_lock(&gp->xprt_close_stack_mutex);
+        if (gp->xprt_close_stack != NULL) {
+                newElement->parent = gp->xprt_close_stack;
+                gp->xprt_close_stack->child = newElement;
+        } else {
+                newElement->parent = NULL;
+	}
+        gp->xprt_close_stack = newElement;
+        pthread_mutex_unlock(&gp->xprt_close_stack_mutex);
+}
+
+void 
+fs2d_cleanup_xprt(fs2d_global_t *gp) {
+	int cnt;	
+	xprt_close_stack_ptr workElement;
+
+/*	CBELog(&gp->fs2,CDB_LE_INTERNAL,cdb_ll_info, "fs2d check main thread... cleanup entered... "); */
+	cnt = 0;
+	/* while stack Elements available */
+	while (fs2d_has_xprt(gp) == TRUE) {	
+		workElement = fs2d_pop_xprt(gp);
+		SVC_DESTROY(workElement->xprt);	
+        	if (workElement != NULL)
+                	free(workElement);
+		cnt++;
+	}
+/*	CBELog(&gp->fs2,CDB_LE_INTERNAL,cdb_ll_info, "fs2d main thread... cleanup %d SVCXPRT's", cnt); */
+}
+
 
 void
 fs2d_destroy_process(fs2d_global_t *gp,fs2d_process_t *process)
@@ -134,7 +192,10 @@
 	}
 	if (process->xprt != NULL) {
 		gp->xprt_table[process->xprt->xp_sock] = NULL;
-		SVC_DESTROY(process->xprt);
+               	if(gp->master_pid == getpid())
+                  SVC_DESTROY(process->xprt);
+                else
+		  fs2d_push_xprt(gp,process->xprt);
 		process->xprt = NULL;
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.