Commit 638f8a2c authored by Ondřej Kuzník's avatar Ondřej Kuzník
Browse files

Tighten checks on retry management

parent 2a813cb0
......@@ -484,9 +484,29 @@ backend_connect_task( void *ctx, void *arg )
return NULL;
}
/*
* Needs exclusive access to the backend.
*/
void
backend_reset( LloadBackend *b )
{
if ( b->b_cookie ) {
int rc;
rc = ldap_pvt_thread_pool_retract( b->b_cookie );
assert( rc == 1 );
b->b_cookie = NULL;
b->b_opening--;
}
if ( event_pending( b->b_retry_event, EV_TIMEOUT, NULL ) ) {
assert( b->b_failed );
event_del( b->b_retry_event );
b->b_opening--;
}
if ( b->b_dns_req ) {
evdns_getaddrinfo_cancel( b->b_dns_req );
b->b_dns_req = NULL;
b->b_opening--;
}
while ( !LDAP_LIST_EMPTY( &b->b_connecting ) ) {
LloadPendingConnection *pending = LDAP_LIST_FIRST( &b->b_connecting );
......@@ -569,6 +589,7 @@ lload_backend_destroy( LloadBackend *b )
"destroying backend uri='%s', numconns=%d, numbindconns=%d\n",
b->b_uri.bv_val, b->b_numconns, b->b_numbindconns );
b->b_numconns = b->b_numbindconns = 0;
backend_reset( b );
LDAP_CIRCLEQ_REMOVE( &backend, b, b_next );
......
......@@ -1389,6 +1389,12 @@ lloadd_daemon( struct event_base *daemon_base )
destroy_listeners();
/* TODO: Mark upstream connections closing */
LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) {
ldap_pvt_thread_mutex_lock( &b->b_mutex );
b->b_numconns = b->b_numbindconns = 0;
backend_reset( b );
ldap_pvt_thread_mutex_unlock( &b->b_mutex );
}
for ( i = 0; i < lload_daemon_threads; i++ ) {
/*
......@@ -1497,12 +1503,6 @@ lload_handle_backend_invalidation( LloadChange *change )
&connection_pool, handle_pdus, backend_conn_cb, b );
ldap_pvt_thread_pool_walk(
&connection_pool, upstream_bind, backend_conn_cb, b );
/* Drop the connection task if it's queued */
if ( b->b_cookie ) {
int rc = ldap_pvt_thread_pool_retract( b->b_cookie );
assert( rc == 1 );
b->b_opening--;
}
lload_backend_destroy( b );
return;
}
......@@ -1586,7 +1586,10 @@ lload_handle_backend_invalidation( LloadChange *change )
b->b_opening--;
need_close--;
}
event_del( b->b_retry_event );
if ( event_pending( b->b_retry_event, EV_TIMEOUT, NULL ) ) {
event_del( b->b_retry_event );
b->b_opening--;
}
assert( b->b_opening == 0 );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment