Commit 0cfd4fca authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Ondřej Kuzník
Browse files

Make timeouts common and redo connection read timeouts

parent b4d7e8af
......@@ -526,6 +526,8 @@ option. The authentication configuration is shared between them.
.B [credentials=<passwd>]
.B [realm=<realm>]
.B [secprops=<properties>]
.B [timeout=<seconds>]
.B [network\-timeout=<seconds>]
Specifies the bind credentials
.B lloadd
......@@ -564,14 +566,32 @@ option. A non default SASL realm can be set with the
.B realm
option.
The
.B timeout
parameter indicates how long an operation can be pending a response (result,
search entry, ...) from the server in seconds. Due to how timeouts are
detected, the timeout might not be detected and handled up to
.B timeout
seconds after it happens.
The
.B network\-timeout
parameter sets how long the consumer will wait to establish a
network connection to the provider. Once a connection is
established, the
.B timeout
parameter determines how long the consumer will wait for the initial
Bind request to complete.
Timeout set to 0 means no timeout is in effect and by default, no timeouts are
in effect.
.SH BACKEND OPTIONS
.TP
.B backend
.B uri=ldap[s]://<hostname>[:port]
.B [retry=<retry interval in ms>]
.B [network\-timeout=<seconds>]
.B [timeout=<seconds>]
.B [keepalive=<idle>:<probes>:<interval>]
.B [starttls=yes|critical]
.B [tls_cert=<file>]
......@@ -625,15 +645,6 @@ connections,
.BR 0 ,
the default, means no limit will be imposed for this backend.
The
.B network\-timeout
parameter sets how long the consumer will wait to establish a
network connection to the provider. Once a connection is
established, the
.B timeout
parameter determines how long the consumer will wait for the initial
Bind request to complete. By default no timeouts are in effect.
The
.B keepalive
parameter sets the values of \fIidle\fP, \fIprobes\fP, and \fIinterval\fP
......
......@@ -143,7 +143,7 @@ upstream_name_cb( int result, struct evutil_addrinfo *res, void *arg )
goto fail;
}
event_add( conn->event, lload_write_timeout );
event_add( conn->event, lload_timeout_net );
LDAP_LIST_INSERT_HEAD( &b->b_connecting, conn, next );
Debug( LDAP_DEBUG_CONNS, "upstream_name_cb: "
"connection to backend uri=%s in progress\n",
......@@ -374,7 +374,7 @@ backend_connect( evutil_socket_t s, short what, void *arg )
goto fail;
}
event_add( conn->event, lload_write_timeout );
event_add( conn->event, lload_timeout_net );
LDAP_LIST_INSERT_HEAD( &b->b_connecting, conn, next );
Debug( LDAP_DEBUG_CONNS, "backend_connect: "
"connection to backend uri=%s in progress\n",
......
......@@ -302,9 +302,10 @@ client_tls_handshake_cb( evutil_socket_t s, short what, void *arg )
event_del( c->c_read_event );
event_del( c->c_write_event );
c->c_read_timeout = NULL;
event_assign( c->c_read_event, base, c->c_fd, EV_READ|EV_PERSIST,
connection_read_cb, c );
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
event_assign( c->c_write_event, base, c->c_fd, EV_WRITE,
connection_write_cb, c );
......@@ -374,6 +375,7 @@ client_init(
if ( rc ) {
c->c_refcnt++;
c->c_read_timeout = lload_timeout_net;
read_cb = write_cb = client_tls_handshake_cb;
}
}
......@@ -385,7 +387,7 @@ client_init(
goto fail;
}
c->c_read_event = event;
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
event = event_new( base, s, EV_WRITE, write_cb, c );
if ( !event ) {
......
......@@ -69,7 +69,7 @@ char *global_host = NULL;
static FILE *logfile;
static char *logfileName;
static struct timeval timeout_write_tv = { 10, 0 };
static struct timeval timeout_net_tv, timeout_write_tv = { 10, 0 };
lload_features_t lload_features;
......@@ -78,6 +78,7 @@ ber_len_t sockbuf_max_incoming_upstream = LLOAD_SB_MAX_INCOMING_UPSTREAM;
int slap_conn_max_pdus_per_cycle = LLOAD_CONN_MAX_PDUS_PER_CYCLE_DEFAULT;
struct timeval *lload_timeout_net = NULL;
struct timeval *lload_write_timeout = &timeout_write_tv;
char *slapd_pid_file = NULL;
......@@ -664,6 +665,13 @@ config_bindconf( ConfigArgs *c )
*ptr = '\0';
}
if ( bindconf.sb_timeout_net ) {
timeout_net_tv.tv_sec = bindconf.sb_timeout_net;
lload_timeout_net = &timeout_net_tv;
} else {
lload_timeout_net = NULL;
}
#ifdef HAVE_TLS
if ( bindconf.sb_tls_do_init ) {
bindconf_tls_set( &bindconf, slap_tls_backend_ld );
......
......@@ -128,7 +128,7 @@ handle_pdus( void *ctx, void *arg )
}
}
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
Debug( LDAP_DEBUG_CONNS, "handle_pdus: "
"re-enabled read event on connid=%lu\n",
c->c_connid );
......@@ -211,7 +211,7 @@ connection_read_cb( evutil_socket_t s, short what, void *arg )
CONNECTION_DESTROY(c);
return;
}
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
Debug( LDAP_DEBUG_CONNS, "connection_read_cb: "
"re-enabled read event on connid=%lu\n",
c->c_connid );
......
......@@ -83,9 +83,10 @@ handle_starttls( Connection *c, Operation *op )
ldap_pvt_thread_mutex_unlock( &c->c_io_mutex );
CONNECTION_LOCK_DECREF(c);
c->c_read_timeout = lload_timeout_net;
event_assign( c->c_read_event, base, c->c_fd, EV_READ|EV_PERSIST,
client_tls_handshake_cb, c );
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
event_assign( c->c_write_event, base, c->c_fd, EV_WRITE,
client_tls_handshake_cb, c );
......
......@@ -254,6 +254,7 @@ LDAP_SLAPD_V (const char) Versionstr[];
LDAP_SLAPD_V (int) global_gentlehup;
LDAP_SLAPD_V (int) global_idletimeout;
LDAP_SLAPD_V (struct timeval *) lload_timeout_net;
LDAP_SLAPD_V (struct timeval *) lload_write_timeout;
LDAP_SLAPD_V (char *) global_host;
......
......@@ -383,6 +383,7 @@ struct Connection {
/* must not be used while holding either mutex */
struct event *c_read_event, *c_write_event;
struct timeval *c_read_timeout;
/* can only be changed by binding thread */
struct berval c_sasl_bind_mech; /* mech in progress */
......
......@@ -292,6 +292,11 @@ upstream_bind_cb( Connection *c )
c->c_pdu_cb = handle_one_response;
c->c_state = LLOAD_C_READY;
c->c_type = LLOAD_C_OPEN;
c->c_read_timeout = NULL;
event_add( c->c_read_event, c->c_read_timeout );
Debug( LDAP_DEBUG_CONNS, "upstream_bind_cb: "
"connid=%lu finished binding, now active\n",
c->c_connid );
CONNECTION_UNLOCK_INCREF(c);
ldap_pvt_thread_mutex_lock( &b->b_mutex );
LDAP_CIRCLEQ_REMOVE( &b->b_preparing, c, c_next );
......@@ -365,6 +370,8 @@ upstream_bind( void *ctx, void *arg )
connection_write_cb( -1, 0, c );
CONNECTION_LOCK_DECREF(c);
c->c_read_timeout = lload_timeout_net;
event_add( c->c_read_event, c->c_read_timeout );
CONNECTION_UNLOCK_OR_DESTROY(c);
return NULL;
......@@ -459,9 +466,10 @@ upstream_tls_handshake_cb( evutil_socket_t s, short what, void *arg )
event_del( c->c_read_event );
event_del( c->c_write_event );
c->c_read_timeout = NULL;
event_assign( c->c_read_event, base, c->c_fd, EV_READ|EV_PERSIST,
connection_read_cb, c );
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
event_assign( c->c_write_event, base, c->c_fd, EV_WRITE,
connection_write_cb, c );
......@@ -581,12 +589,13 @@ upstream_starttls( Connection *c )
event_del( c->c_read_event );
event_del( c->c_write_event );
c->c_read_timeout = lload_timeout_net;
event_assign( c->c_read_event, base, c->c_fd, EV_READ|EV_PERSIST,
upstream_tls_handshake_cb, c );
event_assign( c->c_write_event, base, c->c_fd, EV_WRITE,
upstream_tls_handshake_cb, c );
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
event_add( c->c_write_event, lload_write_timeout );
CONNECTION_UNLOCK(c);
......@@ -678,7 +687,7 @@ upstream_init( ber_socket_t s, Backend *b )
connection_write_cb( s, 0, c );
CONNECTION_LOCK_DECREF(c);
}
event_add( c->c_read_event, NULL );
event_add( c->c_read_event, c->c_read_timeout );
c->c_destroy = upstream_destroy;
CONNECTION_UNLOCK_OR_DESTROY(c);
......
Supports Markdown
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