From: Howard Chu Date: Fri, 19 May 2006 22:47:33 +0000 (+0000) Subject: Fix idletimeout deadlock X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~236 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9de3d9c27734140f4ac3c78a9f3eafdbf25a7a50;p=openldap Fix idletimeout deadlock --- diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 4cf698c15b..41dcb363e8 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -919,6 +919,17 @@ Connection* connection_next( Connection *c, ber_socket_t *index ) if( connections[*index].c_struct_state == SLAP_C_USED ) { assert( connections[*index].c_conn_state != SLAP_C_INVALID ); c = &connections[(*index)++]; + if ( ldap_pvt_thread_mutex_trylock( &c->c_mutex )) { + /* avoid deadlock */ + ldap_pvt_thread_mutex_unlock( &connections_mutex ); + ldap_pvt_thread_mutex_lock( &c->c_mutex ); + ldap_pvt_thread_mutex_lock( &connections_mutex ); + if ( c->c_struct_state != SLAP_C_USED ) { + ldap_pvt_thread_mutex_unlock( &c->c_mutex ); + c = NULL; + continue; + } + } break; } @@ -926,7 +937,6 @@ Connection* connection_next( Connection *c, ber_socket_t *index ) assert( connections[*index].c_conn_state == SLAP_C_INVALID ); } - if( c != NULL ) ldap_pvt_thread_mutex_lock( &c->c_mutex ); ldap_pvt_thread_mutex_unlock( &connections_mutex ); return c; }