[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#4395) slapd in endless loop when opening to many connections



As I got: 452 Error writing file: No space left on device.
from ftp.openldap.org here is a patch that made it working for me.
Please review and comment.
------------------------------------------------------------------------
--- servers/slapd/daemon.c	25 Jan 2006 00:36:18 -0000	1.377
+++ servers/slapd/daemon.c	10 Feb 2006 16:50:00 -0000
@@ -222,6 +222,7 @@
 
 # define SLAP_EVENT_IS_READ(i)	SLAP_CHK_EVENT((i), EPOLLIN)
 # define SLAP_EVENT_IS_WRITE(i)	SLAP_CHK_EVENT((i), EPOLLOUT)
+# define SLAP_EVENT_IS_ERR(i)	SLAP_CHK_EVENT((i), EPOLLERR)
 # define SLAP_EVENT_IS_LISTENER(i)	SLAP_EV_LISTENER(revents[(i)].data.ptr)
 # define SLAP_EVENT_LISTENER(i)	((Listener *)(revents[(i)].data.ptr))
 
@@ -2132,6 +2133,9 @@
 					connection_read( fd );
 #endif
 				}
+				if( SLAP_EVENT_IS_ERR( i ) ) {
+			            connection_shutdown( fd );
+                                }
 			}
 		}
 #endif	/* SLAP_EVENTS_ARE_INDEXED */
--- servers/slapd/connection.c	6 Jan 2006 15:24:37 -0000	1.348
+++ servers/slapd/connection.c	10 Feb 2006 16:50:43 -0000
@@ -2252,3 +2252,32 @@
 	conn->c_connid = conn_nextid++;
 	ldap_pvt_thread_mutex_unlock( &conn_nextid_mutex );
 }
+
+int connection_shutdown(ber_socket_t s)
+{
+	int rc = 0;
+	Connection *c;
+
+	assert( connections != NULL );
+
+	ldap_pvt_thread_mutex_lock( MCA_GET_CONN_MUTEX(s) );
+
+	/* get (locked) connection */
+	c = connection_get( s );
+
+	if( c == NULL ) {
+		Debug( LDAP_DEBUG_ANY,
+			"connection_read(%ld): no connection!\n",
+			(long) s, 0, 0 );
+
+		ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
+		return -1;
+	}
+
+        connection_closing( c, conn_lost_str );
+        connection_close( c );
+        connection_return( c );
+	ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
+
+	return 0;
+}
--- servers/slapd/proto-slap.h	10 Feb 2006 07:21:10 -0000	1.667
+++ servers/slapd/proto-slap.h	10 Feb 2006 16:50:56 -0000
@@ -654,6 +654,7 @@
 LDAP_SLAPD_F (int) connection_read LDAP_P((ber_socket_t s));
 #endif
 
+LDAP_SLAPD_F (int) connection_shutdown LDAP_P((ber_socket_t s));
 LDAP_SLAPD_F (unsigned long) connections_nextid(void);
 
 LDAP_SLAPD_F (Connection *) connection_first LDAP_P(( ber_socket_t * ));