Fix prev commit, don't timeout outbound connections

This commit is contained in:
Howard Chu 2003-10-25 21:14:07 +00:00
parent 45c42630db
commit 782d1be0ad
4 changed files with 51 additions and 31 deletions

View File

@ -203,8 +203,10 @@ int connections_timeout_idle(time_t now)
c != NULL; c != NULL;
c = connection_next( c, &connindex ) ) c = connection_next( c, &connindex ) )
{ {
/* Don't timeout a slow-running request */ /* Don't timeout a slow-running request or a persistent
if( c->c_n_ops_executing ) continue; * outbound connection */
if( c->c_n_ops_executing ||
c->c_conn_state == SLAP_C_CLIENT ) continue;
if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) { if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) {
/* close it */ /* close it */
@ -689,7 +691,7 @@ connection_destroy( Connection *c )
ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd ); ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
if ( sd != AC_SOCKET_INVALID ) { if ( sd != AC_SOCKET_INVALID ) {
slapd_remove( sd, 0 ); slapd_remove( sd, 1, 0 );
Statslog( LDAP_DEBUG_STATS, Statslog( LDAP_DEBUG_STATS,
"conn=%lu fd=%ld closed\n", "conn=%lu fd=%ld closed\n",
@ -1151,7 +1153,7 @@ int connection_client_setup(
c->c_clientfunc = func; c->c_clientfunc = func;
c->c_clientarg = arg; c->c_clientarg = arg;
connection_return( c ); connection_return( c );
slapd_add_internal( s ); slapd_add_internal( s, 0 );
slapd_set_read( s, 1 ); slapd_set_read( s, 1 );
return 0; return 0;
} }
@ -1178,6 +1180,7 @@ void connection_client_stop(
c->c_conn_state = SLAP_C_INVALID; c->c_conn_state = SLAP_C_INVALID;
c->c_struct_state = SLAP_C_UNUSED; c->c_struct_state = SLAP_C_UNUSED;
connection_return( c ); connection_return( c );
slapd_remove( s, 0, 0 );
} }
int connection_read(ber_socket_t s) int connection_read(ber_socket_t s)
@ -1201,7 +1204,7 @@ int connection_read(ber_socket_t s)
"connection_read(%ld): no connection!\n", "connection_read(%ld): no connection!\n",
(long) s, 0, 0 ); (long) s, 0, 0 );
#endif #endif
slapd_remove(s, 0); slapd_remove(s, 1, 0);
ldap_pvt_thread_mutex_unlock( &connections_mutex ); ldap_pvt_thread_mutex_unlock( &connections_mutex );
return -1; return -1;
@ -1790,7 +1793,7 @@ int connection_write(ber_socket_t s)
"connection_write(%ld): no connection!\n", "connection_write(%ld): no connection!\n",
(long) s, 0, 0 ); (long) s, 0, 0 );
#endif #endif
slapd_remove(s, 0); slapd_remove(s, 1, 0);
ldap_pvt_thread_mutex_unlock( &connections_mutex ); ldap_pvt_thread_mutex_unlock( &connections_mutex );
return -1; return -1;
} }

View File

@ -195,8 +195,13 @@ void slapd_slp_dereg() {
/* /*
* Add a descriptor to daemon control * Add a descriptor to daemon control
*
* If isactive, the descriptor is a live server session and is subject
* to idletimeout control. Otherwise, the descriptor is a passive
* listener or an outbound client session, and not subject to
* idletimeout.
*/ */
static void slapd_add(ber_socket_t s) { static void slapd_add(ber_socket_t s, int isactive) {
ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
assert( !FD_ISSET( s, &slap_daemon.sd_actives )); assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
@ -209,7 +214,9 @@ static void slapd_add(ber_socket_t s) {
} }
#endif #endif
slap_daemon.sd_nactives++; if ( isactive ) {
slap_daemon.sd_nactives++;
}
FD_SET( s, &slap_daemon.sd_actives ); FD_SET( s, &slap_daemon.sd_actives );
FD_SET( s, &slap_daemon.sd_readers ); FD_SET( s, &slap_daemon.sd_readers );
@ -231,10 +238,12 @@ static void slapd_add(ber_socket_t s) {
/* /*
* Remove the descriptor from daemon control * Remove the descriptor from daemon control
*/ */
void slapd_remove(ber_socket_t s, int wake) { void slapd_remove(ber_socket_t s, int wasactive, int wake) {
ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
slap_daemon.sd_nactives--; if ( wasactive ) {
slap_daemon.sd_nactives--;
}
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG( CONNECTION, DETAIL1, LDAP_LOG( CONNECTION, DETAIL1,
@ -1119,7 +1128,7 @@ close_listeners(
for ( l = 0; slap_listeners[l] != NULL; l++ ) { for ( l = 0; slap_listeners[l] != NULL; l++ ) {
if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) { if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
if ( remove ) if ( remove )
slapd_remove( slap_listeners[l]->sl_sd, 0 ); slapd_remove( slap_listeners[l]->sl_sd, 0, 0 );
#ifdef LDAP_PF_LOCAL #ifdef LDAP_PF_LOCAL
if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) { if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path ); unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
@ -1171,7 +1180,7 @@ slapd_daemon_task(
* are unnecessary. * are unnecessary.
*/ */
if ( slap_listeners[l]->sl_is_udp ) { if ( slap_listeners[l]->sl_is_udp ) {
slapd_add( slap_listeners[l]->sl_sd ); slapd_add( slap_listeners[l]->sl_sd, 1 );
continue; continue;
} }
#endif #endif
@ -1228,7 +1237,7 @@ slapd_daemon_task(
return( (void*)-1 ); return( (void*)-1 );
} }
slapd_add( slap_listeners[l]->sl_sd ); slapd_add( slap_listeners[l]->sl_sd, 0 );
} }
#ifdef HAVE_NT_SERVICE_MANAGER #ifdef HAVE_NT_SERVICE_MANAGER
@ -1332,11 +1341,6 @@ slapd_daemon_task(
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex ); ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
if ( !at ) {
at = ldap_pvt_thread_pool_backload(&connection_pool) -
ldap_pvt_runqueue_persistent_backload( &syncrepl_rq );
}
if ( at if ( at
#if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS) #if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS)
&& ( tv.tv_sec || tv.tv_usec ) && ( tv.tv_sec || tv.tv_usec )
@ -1350,10 +1354,10 @@ slapd_daemon_task(
rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat ); rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
while ( cat && cat->tv_sec && cat->tv_sec <= now ) { while ( cat && cat->tv_sec && cat->tv_sec <= now ) {
if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) { if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
ldap_pvt_runqueue_resched( &syncrepl_rq, rtask ); ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
} else { } else {
ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask ); ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask );
ldap_pvt_runqueue_resched( &syncrepl_rq, rtask ); ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
ldap_pvt_thread_pool_submit( &connection_pool, ldap_pvt_thread_pool_submit( &connection_pool,
rtask->routine, (void *) rtask ); rtask->routine, (void *) rtask );
@ -1769,7 +1773,7 @@ slapd_daemon_task(
slap_listeners[l]->sl_name.bv_val, slap_listeners[l]->sl_name.bv_val,
0 ); 0 );
slapd_add( s ); slapd_add( s, 1 );
continue; continue;
} }
@ -2105,8 +2109,8 @@ slap_sig_wake( int sig )
} }
void slapd_add_internal(ber_socket_t s) { void slapd_add_internal(ber_socket_t s, int isactive) {
slapd_add(s); slapd_add(s, isactive);
} }
Listener ** slapd_get_listeners(void) { Listener ** slapd_get_listeners(void) {

View File

@ -382,12 +382,12 @@ LDAP_SLAPD_F (int) slap_get_csn LDAP_P(( Operation *, char *, int, struct berval
/* /*
* daemon.c * daemon.c
*/ */
LDAP_SLAPD_F (void) slapd_add_internal(ber_socket_t s); LDAP_SLAPD_F (void) slapd_add_internal(ber_socket_t s, int isactive);
LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls ); LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls );
LDAP_SLAPD_F (int) slapd_daemon_destroy(void); LDAP_SLAPD_F (int) slapd_daemon_destroy(void);
LDAP_SLAPD_F (int) slapd_daemon(void); LDAP_SLAPD_F (int) slapd_daemon(void);
LDAP_SLAPD_F (Listener **) slapd_get_listeners LDAP_P((void)); LDAP_SLAPD_F (Listener **) slapd_get_listeners LDAP_P((void));
LDAP_SLAPD_F (void) slapd_remove LDAP_P((ber_socket_t s, int wake)); LDAP_SLAPD_F (void) slapd_remove LDAP_P((ber_socket_t s, int wasactive, int wake));
LDAP_SLAPD_F (RETSIGTYPE) slap_sig_shutdown LDAP_P((int sig)); LDAP_SLAPD_F (RETSIGTYPE) slap_sig_shutdown LDAP_P((int sig));
LDAP_SLAPD_F (RETSIGTYPE) slap_sig_wake LDAP_P((int sig)); LDAP_SLAPD_F (RETSIGTYPE) slap_sig_wake LDAP_P((int sig));

View File

@ -689,8 +689,6 @@ do_syncrepl(
} else { } else {
connection_client_enable( s ); connection_client_enable( s );
} }
/* Don't need to resched this task for a while */
if ( rc == 0 ) rc = 1;
} else { } else {
connection_client_stop( s ); connection_client_stop( s );
} }
@ -701,13 +699,28 @@ do_syncrepl(
} }
} }
if ( rc == LDAP_SUCCESS || rc == LDAP_SERVER_DOWN ) { /* At this point, we have 4 cases:
ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); * 1) for any hard failure, give up and remove this task
* 2) for ServerDown, reschedule this task to run
* 3) for Refresh and Success, reschedule to run
* 4) for Persist and Success, reschedule to defer
*/
ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask ); ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
ldap_pvt_runqueue_resched( &syncrepl_rq, rtask );
ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
} }
if ( rc && rc != LDAP_SERVER_DOWN ) {
ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
} else if ( rc == LDAP_SERVER_DOWN ||
si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
rc = 0;
} else {
rc = 1;
}
ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, rc );
ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
return NULL; return NULL;
} }