From d4fda88466dd49910eb562258a3be3dd253e33ec Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 21 Oct 2009 16:39:31 -0400 Subject: Better offline/enumeration behavior Go offline in case of hard errors too. It makes no sense to keep trying too often when you have bad credentials for example. Also delay starting the enumeration thread so that we finish initializations first (bind to ldap is still a blocking operation and this may interfere with clients/monitor registrations). --- server/providers/ldap/ldap_id.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'server') diff --git a/server/providers/ldap/ldap_id.c b/server/providers/ldap/ldap_id.c index 04aaa083..681848f7 100644 --- a/server/providers/ldap/ldap_id.c +++ b/server/providers/ldap/ldap_id.c @@ -219,7 +219,6 @@ static void users_get_done(struct tevent_req *req) const char *error = NULL; int ret = EOK; - if (tevent_req_is_error(req, &tstate, &err)) { ret = err; } @@ -230,6 +229,8 @@ static void users_get_done(struct tevent_req *req) if (ret == ETIMEDOUT) { dp_err = DP_ERR_TIMEOUT; + } + if (ret == ETIMEDOUT || ret == EFAULT) { ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data, struct sdap_id_ctx); be_mark_offline(ctx->be); @@ -395,6 +396,8 @@ static void groups_get_done(struct tevent_req *req) if (ret == ETIMEDOUT) { dp_err = DP_ERR_TIMEOUT; + } + if (ret == ETIMEDOUT || ret == EFAULT) { ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data, struct sdap_id_ctx); be_mark_offline(ctx->be); @@ -535,6 +538,8 @@ static void groups_by_user_done(struct tevent_req *req) if (ret == ETIMEDOUT) { dp_err = DP_ERR_TIMEOUT; + } + if (ret == ETIMEDOUT || ret == EFAULT) { ctx = talloc_get_type(breq->be_ctx->bet_info[BET_ID].pvt_bet_data, struct sdap_id_ctx); be_mark_offline(ctx->be); @@ -804,9 +809,7 @@ fail: DEBUG(9, ("User enumeration failed with: (%d)[%s]\n", (int)err, strerror(err))); - if (err == ETIMEDOUT) { - be_mark_offline(state->ctx->be); - } + be_mark_offline(state->ctx->be); } DEBUG(1, ("Failed to enumerate users, retrying later!\n")); @@ -831,10 +834,8 @@ static void ldap_id_enum_groups_done(struct tevent_req *subreq) return; fail: - if (err == ETIMEDOUT) { - be_mark_offline(state->ctx->be); - } - + /* always go offline on failures */ + be_mark_offline(state->ctx->be); DEBUG(1, ("Failed to enumerate groups, retrying later!\n")); tevent_req_done(req); } @@ -1137,8 +1138,9 @@ int sdap_id_setup_tasks(struct sdap_id_ctx *ctx) /* set up enumeration task */ if (ctx->be->domain->enumerate) { - /* run the first immediately */ - ctx->last_run = tevent_timeval_current(); + /* run the first one in a couple of seconds so that we have time to + * finish initializations first*/ + ctx->last_run = tevent_timeval_current_ofs(2, 0); enum_task = tevent_add_timer(ctx->be->ev, ctx, ctx->last_run, ldap_id_enumerate, ctx); if (!enum_task) { -- cgit