This patch is for debugging LDAP hangs. If LDAP server loses requests, this patch will complain about that. Doesn't look like this happens though. Index: src/auth/db-ldap.c =================================================================== RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.c,v retrieving revision 1.41.2.7 diff -u -r1.41.2.7 db-ldap.c --- src/auth/db-ldap.c 22 Sep 2006 13:26:44 -0000 1.41.2.7 +++ src/auth/db-ldap.c 15 Oct 2006 17:02:12 -0000 @@ -37,6 +37,9 @@ # define LDAP_OPT_SUCCESS LDAP_SUCCESS #endif +#define LDAP_REQUEST_TIMEOUT 60 +#define LDAP_TIMEOUT_CHECK_INTERVAL 10 + #define DEF(type, name) \ { type, #name, offsetof(struct ldap_settings, name) } @@ -150,6 +153,8 @@ } } + request->sent = ioloop_time; + msgid = ldap_search(conn->ld, request->base, scope, request->filter, request->attributes, 0); if (msgid == -1) { @@ -162,6 +167,29 @@ hash_insert(conn->requests, POINTER_CAST(msgid), request); } +#ifdef LDAP_REQUEST_TIMEOUT +static void ldap_requests_check_timeouts(void *context) +{ + struct ldap_connection *conn = context; + struct hash_iterate_context *iter; + void *key, *value; + + iter = hash_iterate_init(conn->requests); + while (hash_iterate(iter, &key, &value)) { + struct ldap_request *request = value; + + if (ioloop_time - request->sent >= LDAP_REQUEST_TIMEOUT) { + i_error("LDAP: Request timed out: base=%s, filter=%s", + request->base, request->filter); + hash_remove(conn->requests, key); + request->callback(conn, request, NULL); + } + } + hash_iterate_deinit(iter); + hash_clear(conn->requests, FALSE); +} +#endif + static void ldap_conn_retry_requests(struct ldap_connection *conn) { struct hash_table *old_requests; @@ -373,6 +401,10 @@ net_set_nonblock(fd, TRUE); conn->io = io_add(fd, IO_READ, ldap_input, conn); +#ifdef LDAP_REQUEST_TIMEOUT + conn->to = timeout_add(LDAP_TIMEOUT_CHECK_INTERVAL, + ldap_requests_check_timeouts, conn); +#endif /* in case there are requests waiting, retry them */ ldap_conn_retry_requests(conn); @@ -399,6 +431,8 @@ if (conn->io != NULL) io_remove(&conn->io); + if (conn->to != NULL) + timeout_remove(&conn->to); if (conn->ld != NULL) { ldap_unbind(conn->ld); Index: src/auth/db-ldap.h =================================================================== RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.h,v retrieving revision 1.20.2.4 diff -u -r1.20.2.4 db-ldap.h --- src/auth/db-ldap.h 19 Jun 2006 16:10:04 -0000 1.20.2.4 +++ src/auth/db-ldap.h 15 Oct 2006 17:02:12 -0000 @@ -57,6 +57,7 @@ LDAP *ld; struct io *io; + struct timeout *to; struct hash_table *requests; char **pass_attr_names, **user_attr_names; @@ -69,6 +70,8 @@ db_search_callback_t *callback; void *context; + time_t sent; + const char *base; const char *filter; char **attributes; /* points to pass_attr_names / user_attr_names */