@@ -87,6 +87,8 @@ extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url, LDAP **ld);
8787#define DEFAULT_ATTRS_COUNT 3 /* The default number of search attributes */
8888#define MAX_ATTRS_COUNT 5 /* Maximum search attributes to display in log */
8989
90+ #define RECONNECT_ASAP_MS 1000 /* Delay (in ms) for LDAP reconnection (when we want ASAP reconnect) */
91+
9092
9193
9294typedef struct {
@@ -123,7 +125,7 @@ typedef struct {
123125 ngx_queue_t free_connections ; /* Queue of free (ready) connections */
124126 ngx_queue_t waiting_requests ; /* Queue of ctx with not finished requests */
125127
126- ngx_queue_t pending_connections ; /* Queue of pending connections (waiting re-connect) */
128+ ngx_queue_t pending_reconnections ; /* Queue of pending connections (waiting re-connect) */
127129 char * * attrs ; /* Search attributes formated for ldap_search_ext() */
128130 ngx_str_t attribute_header_prefix ;
129131} ngx_http_auth_ldap_server_t ;
@@ -225,7 +227,7 @@ typedef struct ngx_http_auth_ldap_connection {
225227#endif
226228
227229 ngx_queue_t queue ; /* Queue element to be chained in server->free_connections queue */
228- ngx_queue_t queue_pending ; /* Queue element to be chained in server->pending_connections queue */
230+ ngx_queue_t queue_pending ; /* Queue element to be chained in server->pending_reconnections queue */
229231 ngx_http_auth_ldap_ctx_t * rctx ;
230232
231233 LDAP * ld ;
@@ -252,8 +254,8 @@ static char * ngx_http_auth_ldap_merge_loc_conf(ngx_conf_t *, void *, void *);
252254static ngx_int_t ngx_http_auth_ldap_init_worker (ngx_cycle_t * cycle );
253255static ngx_int_t ngx_http_auth_ldap_init (ngx_conf_t * cf );
254256static ngx_int_t ngx_http_auth_ldap_init_cache (ngx_cycle_t * cycle );
255- static void ngx_http_auth_ldap_close_connection (ngx_http_auth_ldap_connection_t * c );
256- static void ngx_http_auth_ldap_set_pending_connection (ngx_http_auth_ldap_connection_t * c );
257+ static void ngx_http_auth_ldap_close_connection (ngx_http_auth_ldap_connection_t * c , int retry_asap );
258+ static void ngx_http_auth_ldap_set_pending_reconnection (ngx_http_auth_ldap_connection_t * c , ngx_msec_t reconnect_delay );
257259static void ngx_http_auth_ldap_read_handler (ngx_event_t * rev );
258260static void ngx_http_auth_ldap_connect (ngx_http_auth_ldap_connection_t * c );
259261static void ngx_http_auth_ldap_connect_continue (ngx_http_auth_ldap_connection_t * c );
@@ -1287,7 +1289,7 @@ ngx_http_auth_ldap_sb_close(Sockbuf_IO_Desc *sbiod)
12871289 if (ngx_shutdown_socket (c -> conn .connection -> fd , SHUT_RDWR ) == -1 ) {
12881290 ngx_connection_error (c -> conn .connection , ngx_socket_errno , ngx_shutdown_socket_n " failed" );
12891291 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_sb_close() Cnx[%d] shutdown failed" , c -> cnx_idx );
1290- ngx_http_auth_ldap_close_connection (c );
1292+ ngx_http_auth_ldap_close_connection (c , 0 );
12911293 return -1 ;
12921294 }
12931295 }
@@ -1322,6 +1324,7 @@ ngx_http_auth_ldap_sb_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
13221324 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_sb_read(len=%d) Cnx[%d]" , len , c -> cnx_idx );
13231325
13241326 ret = c -> conn .connection -> recv (c -> conn .connection , buf , len );
1327+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_sb_read Cnx[%d] recv ret=%d" , c -> cnx_idx , ret );
13251328 if (ret < 0 ) {
13261329 errno = (ret == NGX_AGAIN ) ? NGX_EAGAIN : NGX_ECONNRESET ;
13271330 return -1 ;
@@ -1362,11 +1365,12 @@ static Sockbuf_IO ngx_http_auth_ldap_sbio =
13621365/*** Asynchronous LDAP connection handling ***/
13631366
13641367static void
1365- ngx_http_auth_ldap_close_connection (ngx_http_auth_ldap_connection_t * c )
1368+ ngx_http_auth_ldap_close_connection (ngx_http_auth_ldap_connection_t * c , int retry_asap )
13661369{
13671370 ngx_queue_t * q ;
1371+ ngx_msec_t reconnect_delay = retry_asap ? RECONNECT_ASAP_MS : c -> server -> reconnect_timeout ; // Default reconnect delay
13681372
1369- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_close_connection: Cnx[%d]" , c -> cnx_idx );
1373+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_close_connection: Cnx[%d] retry_asap=%d " , c -> cnx_idx , retry_asap );
13701374
13711375 if (c -> ld ) {
13721376 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_close_connection: Cnx[%d] Unbinding from the server \"%V\")" ,
@@ -1409,7 +1413,7 @@ ngx_http_auth_ldap_close_connection(ngx_http_auth_ldap_connection_t *c)
14091413 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
14101414 "ngx_http_auth_ldap_close_connection: Cnx[%d] set pending reconnection" ,
14111415 c -> cnx_idx );
1412- ngx_http_auth_ldap_set_pending_connection ( c );
1416+ ngx_http_auth_ldap_set_pending_reconnection ( c , reconnect_delay );
14131417 }
14141418}
14151419
@@ -1452,13 +1456,14 @@ ngx_http_auth_ldap_get_connection(ngx_http_auth_ldap_ctx_t *ctx)
14521456 }
14531457
14541458 /* Check if we have pending (waiting reconnect) connection */
1455- if (!ngx_queue_empty (& server -> pending_connections )) {
1456- q = ngx_queue_head (& server -> pending_connections );
1459+ if (!ngx_queue_empty (& server -> pending_reconnections )) {
1460+ q = ngx_queue_head (& server -> pending_reconnections );
14571461 c = ngx_queue_data (q , ngx_http_auth_ldap_connection_t , queue_pending );
14581462 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , ctx -> r -> connection -> log , 0 ,
14591463 "ngx_http_auth_ldap_get_connection: Got cnx [%d] from pending queue -> shorten reconnect timer" , c -> cnx_idx );
1460- /* Shorten the reconnection timer */
1461- ngx_add_timer (& c -> reconnect_event , 1 );
1464+ /* Use the shortest the reconnection delay as we really need a new connection here */
1465+ ngx_del_timer (& c -> reconnect_event ); // Cancel the reconnect timer
1466+ ngx_add_timer (& c -> reconnect_event , RECONNECT_ASAP_MS );
14621467 }
14631468
14641469 q = ngx_queue_next (& server -> waiting_requests );
@@ -1501,29 +1506,29 @@ ngx_http_auth_ldap_return_connection(ngx_http_auth_ldap_connection_t *c)
15011506}
15021507
15031508static void
1504- ngx_http_auth_ldap_set_pending_connection (ngx_http_auth_ldap_connection_t * c )
1509+ ngx_http_auth_ldap_set_pending_reconnection (ngx_http_auth_ldap_connection_t * c , ngx_msec_t reconnect_delay )
15051510{
15061511 ngx_queue_t * q ;
15071512
15081513 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
1509- "ngx_http_auth_ldap_set_pending_connection : Connection [%d] scheduled for reconnection in %d ms" ,
1510- c -> cnx_idx , c -> server -> reconnect_timeout );
1511- ngx_add_timer (& c -> reconnect_event , c -> server -> reconnect_timeout );
1514+ "ngx_http_auth_ldap_set_pending_reconnection : Connection [%d] scheduled for reconnection in %d ms" ,
1515+ c -> cnx_idx , reconnect_delay );
1516+ ngx_add_timer (& c -> reconnect_event , reconnect_delay );
15121517
15131518 /* Check if connection is already in the pending queue */
1514- for (q = ngx_queue_head (& c -> server -> pending_connections );
1515- q != ngx_queue_sentinel (& c -> server -> pending_connections );
1519+ for (q = ngx_queue_head (& c -> server -> pending_reconnections );
1520+ q != ngx_queue_sentinel (& c -> server -> pending_reconnections );
15161521 q = ngx_queue_next (q ))
15171522 {
15181523 if (q == & c -> queue_pending ) {
15191524 ngx_log_error (NGX_LOG_WARN , c -> log , 0 ,
1520- "http_auth_ldap: ngx_http_auth_ldap_set_pending_connection : Connection already in pending queue" );
1525+ "http_auth_ldap: ngx_http_auth_ldap_set_pending_reconnection : Connection already in pending queue" );
15211526 return ;
15221527 }
15231528 }
15241529 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
1525- "ngx_http_auth_ldap_set_pending_connection : Connection [%d] inserted in pending queue" , c -> cnx_idx );
1526- ngx_queue_insert_tail (& c -> server -> pending_connections , & c -> queue_pending );
1530+ "ngx_http_auth_ldap_set_pending_reconnection : Connection [%d] inserted in pending queue" , c -> cnx_idx );
1531+ ngx_queue_insert_tail (& c -> server -> pending_reconnections , & c -> queue_pending );
15271532}
15281533
15291534static void
@@ -1554,7 +1559,7 @@ ngx_http_auth_ldap_dummy_write_handler(ngx_event_t *wev)
15541559 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , wev -> log , 0 , "http_auth_ldap: Dummy write handler" );
15551560
15561561 if (ngx_handle_write_event (wev , 0 ) != NGX_OK ) {
1557- ngx_http_auth_ldap_close_connection (((ngx_connection_t * ) wev -> data )-> data );
1562+ ngx_http_auth_ldap_close_connection (((ngx_connection_t * ) wev -> data )-> data , 0 );
15581563 }
15591564}
15601565
@@ -1609,23 +1614,23 @@ ngx_http_auth_ldap_connection_established(ngx_http_auth_ldap_connection_t *c)
16091614 rc = ldap_init_fd (c -> conn .connection -> fd , LDAP_PROTO_EXT , (const char * ) c -> server -> url .data , & c -> ld );
16101615 if (rc != LDAP_SUCCESS ) {
16111616 ngx_log_error (NGX_LOG_ERR , c -> log , errno , "ngx_http_auth_ldap_connection_established: ldap_init_fd() failed (%d: %s)" , rc , ldap_err2string (rc ));
1612- ngx_http_auth_ldap_close_connection (c );
1617+ ngx_http_auth_ldap_close_connection (c , 0 );
16131618 return ;
16141619 }
16151620
16161621 if (c -> server -> referral == 0 ) {
16171622 rc = ldap_set_option (c -> ld , LDAP_OPT_REFERRALS , LDAP_OPT_OFF );
16181623 if (rc != LDAP_OPT_SUCCESS ) {
16191624 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_connection_established: ldap_set_option() failed (%d: %s)" , rc , ldap_err2string (rc ));
1620- ngx_http_auth_ldap_close_connection (c );
1625+ ngx_http_auth_ldap_close_connection (c , 0 );
16211626 return ;
16221627 }
16231628 }
16241629
16251630 rc = ldap_get_option (c -> ld , LDAP_OPT_SOCKBUF , (void * ) & sb );
16261631 if (rc != LDAP_OPT_SUCCESS ) {
16271632 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_connection_established: ldap_get_option() failed (%d: %s)" , rc , ldap_err2string (rc ));
1628- ngx_http_auth_ldap_close_connection (c );
1633+ ngx_http_auth_ldap_close_connection (c , 0 );
16291634 return ;
16301635 }
16311636
@@ -1644,7 +1649,7 @@ ngx_http_auth_ldap_connection_established(ngx_http_auth_ldap_connection_t *c)
16441649 ngx_log_error (NGX_LOG_ERR , c -> log , 0 ,
16451650 "ngx_http_auth_ldap_connection_established: [%d] initial ldap_sasl_bind() failed (%d: %s)" ,
16461651 c -> cnx_idx , rc , ldap_err2string (rc ));
1647- ngx_http_auth_ldap_close_connection (c );
1652+ ngx_http_auth_ldap_close_connection (c , 0 );
16481653 return ;
16491654 }
16501655 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
@@ -1694,7 +1699,7 @@ ngx_http_auth_ldap_ssl_handshake_handler(ngx_connection_t *conn, ngx_flag_t vali
16941699 if (conn_sockaddr -> sa_family == AF_INET ) len = 4 ;
16951700 else if (conn_sockaddr -> sa_family == AF_INET6 ) len = 16 ;
16961701 else { // very unlikely indeed
1697- ngx_http_auth_ldap_close_connection (c );
1702+ ngx_http_auth_ldap_close_connection (c , 0 );
16981703 return ;
16991704 }
17001705 addr_verified = X509_check_ip (cert , (const unsigned char * )conn_sockaddr -> sa_data , len , 0 );
@@ -1713,7 +1718,7 @@ ngx_http_auth_ldap_ssl_handshake_handler(ngx_connection_t *conn, ngx_flag_t vali
17131718 "http_auth_ldap: Remote side presented invalid SSL certificate: error %l, %s" ,
17141719 chain_verified , X509_verify_cert_error_string (chain_verified ));
17151720 }
1716- ngx_http_auth_ldap_close_connection (c );
1721+ ngx_http_auth_ldap_close_connection (c , 0 );
17171722 return ;
17181723 }
17191724 }
@@ -1727,7 +1732,7 @@ ngx_http_auth_ldap_ssl_handshake_handler(ngx_connection_t *conn, ngx_flag_t vali
17271732 }
17281733 else { // handshake failed
17291734 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "http_auth_ldap: SSL handshake failed" );
1730- ngx_http_auth_ldap_close_connection (c );
1735+ ngx_http_auth_ldap_close_connection (c , 0 );
17311736 }
17321737}
17331738
@@ -1752,7 +1757,7 @@ ngx_http_auth_ldap_ssl_handshake(ngx_http_auth_ldap_connection_t *c)
17521757 rc = ngx_ssl_create_connection (c -> ssl , c -> conn .connection , NGX_SSL_BUFFER | NGX_SSL_CLIENT );
17531758 if (rc != NGX_OK ) {
17541759 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "http_auth_ldap: SSL initialization failed" );
1755- ngx_http_auth_ldap_close_connection (c );
1760+ ngx_http_auth_ldap_close_connection (c , 0 );
17561761 return ;
17571762 }
17581763
@@ -1822,7 +1827,7 @@ ngx_http_auth_ldap_connect_handler(ngx_event_t *wev)
18221827 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "ngx_http_auth_ldap_connect_handler: Cnx[%d]" , c -> cnx_idx );
18231828
18241829 if (ngx_handle_write_event (wev , 0 ) != NGX_OK ) {
1825- ngx_http_auth_ldap_close_connection (c );
1830+ ngx_http_auth_ldap_close_connection (c , 0 );
18261831 return ;
18271832 }
18281833
@@ -1861,15 +1866,15 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
18611866
18621867 if (c -> ld == NULL ) {
18631868 ngx_log_error (NGX_LOG_ERR , rev -> log , 0 , "ngx_http_auth_ldap_read_handler: Cnx[%d] No LDAP" , c -> cnx_idx );
1864- ngx_http_auth_ldap_close_connection (c );
1869+ ngx_http_auth_ldap_close_connection (c , 0 );
18651870 return ;
18661871 }
18671872
18681873 if (rev -> timedout ) {
18691874 ngx_log_error (NGX_LOG_ERR , c -> log , NGX_ETIMEDOUT ,
1870- "ngx_http_auth_ldap_read_handler: Cnx[%d] Request timed out (state=%d)" , c -> cnx_idx , c -> state );
1875+ "ngx_http_auth_ldap_read_handler: Cnx[%d] Read timed out (state=%d)" , c -> cnx_idx , c -> state );
18711876 conn -> timedout = 1 ;
1872- ngx_http_auth_ldap_close_connection (c );
1877+ ngx_http_auth_ldap_close_connection (c , 1 );
18731878 return ;
18741879 }
18751880
@@ -1880,8 +1885,8 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
18801885 if (rc < 0 ) {
18811886 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_read_handler: Cnx[%d] ldap_result() failed (%d: %s)" ,
18821887 c -> cnx_idx , rc , ldap_err2string (rc ));
1883- ngx_http_auth_ldap_close_connection ( c ) ;
1884-
1888+ int reconnect_asap = 0 ;
1889+
18851890 // if LDAP_SERVER_DOWN (usually timeouts or server disconnects)
18861891 if (rc == LDAP_SERVER_DOWN ) {
18871892 if (c -> server -> max_down_retries_count < c -> server -> max_down_retries ) {
@@ -1893,16 +1898,12 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
18931898 c -> server -> max_down_retries_count ++ ;
18941899 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_read_handler: Cnx[%d] LDAP_SERVER_DOWN: retry count: %d" ,
18951900 c -> cnx_idx , c -> server -> max_down_retries_count );
1896- c -> state = STATE_DISCONNECTED ;
1897- // immediate reconnect synchronously, this schedules another
1898- // timer call to this read handler again
1899- //ngx_http_auth_ldap_reconnect_handler(rev);
1900- ngx_del_timer (& c -> reconnect_event ); // Cancel the reconnect timer
1901- ngx_http_auth_ldap_reconnect_from_connection (c );
1901+ reconnect_asap = 1 ;
19021902 } else {
19031903 ngx_log_error (NGX_LOG_ERR , c -> log , 0 ,
19041904 "ngx_http_auth_ldap_read_handler: Cnx[%d] LDAP_SERVER_DOWN: No more reconnect retry" , c -> cnx_idx );
19051905 }
1906+ ngx_http_auth_ldap_close_connection (c , reconnect_asap );
19061907 }
19071908
19081909 return ;
@@ -1929,7 +1930,7 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
19291930 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_read_handler: Cnx[%d] ldap_parse_result() failed (%d: %s)" ,
19301931 c -> cnx_idx , rc , ldap_err2string (rc ));
19311932 ldap_msgfree (result );
1932- ngx_http_auth_ldap_close_connection (c );
1933+ ngx_http_auth_ldap_close_connection (c , 1 );
19331934 return ;
19341935 }
19351936
@@ -1948,7 +1949,7 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
19481949 c -> cnx_idx , error_code , ldap_err2string (error_code ), error_msg ? error_msg : "-" );
19491950 ldap_memfree (error_msg );
19501951 ldap_msgfree (result );
1951- ngx_http_auth_ldap_close_connection (c );
1952+ ngx_http_auth_ldap_close_connection (c , 0 );
19521953 return ;
19531954 }
19541955 break ;
@@ -2033,7 +2034,7 @@ ngx_http_auth_ldap_read_handler(ngx_event_t *rev)
20332034 }
20342035
20352036 if (ngx_handle_read_event (rev , 0 ) != NGX_OK ) {
2036- ngx_http_auth_ldap_close_connection (c );
2037+ ngx_http_auth_ldap_close_connection (c , 1 );
20372038 return ;
20382039 }
20392040}
@@ -2127,7 +2128,7 @@ ngx_http_auth_ldap_connect_continue(ngx_http_auth_ldap_connection_t *c)
21272128 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED ) {
21282129 ngx_log_error (NGX_LOG_ERR , c -> log , 0 , "ngx_http_auth_ldap_connect_continue: Cnx[%d] Unable to connect to LDAP server \"%V\"." ,
21292130 c -> cnx_idx , & addr -> name );
2130- ngx_http_auth_ldap_set_pending_connection ( c );
2131+ ngx_http_auth_ldap_set_pending_reconnection ( c , c -> server -> reconnect_timeout );
21312132 return ;
21322133 }
21332134
@@ -2150,7 +2151,7 @@ ngx_http_auth_ldap_connect_continue(ngx_http_auth_ldap_connection_t *c)
21502151static void
21512152ngx_http_auth_ldap_connection_cleanup (void * data )
21522153{
2153- ngx_http_auth_ldap_close_connection ((ngx_http_auth_ldap_connection_t * ) data );
2154+ ngx_http_auth_ldap_close_connection ((ngx_http_auth_ldap_connection_t * ) data , 0 );
21542155}
21552156
21562157static void
@@ -2173,15 +2174,15 @@ ngx_http_auth_ldap_reconnect_from_connection(ngx_http_auth_ldap_connection_t *c)
21732174 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
21742175 "ngx_http_auth_ldap_reconnect_from_connection: Cnx[%d] c=0x%p" , c -> cnx_idx , c );
21752176
2176- /* Remove this connection from the pending queue */
2177- for (q = ngx_queue_head (& c -> server -> pending_connections );
2178- q != ngx_queue_sentinel (& c -> server -> pending_connections );
2177+ /* Remove this connection from the pending reconnection queue */
2178+ for (q = ngx_queue_head (& c -> server -> pending_reconnections );
2179+ q != ngx_queue_sentinel (& c -> server -> pending_reconnections );
21792180 q = ngx_queue_next (q ))
21802181 {
21812182 if (q == & c -> queue_pending ) {
21822183 ngx_queue_remove (q );
21832184 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , c -> log , 0 ,
2184- "ngx_http_auth_ldap_reconnect_from_connection: Cnx[%d] removed from pending queue" , c -> cnx_idx );
2185+ "ngx_http_auth_ldap_reconnect_from_connection: Cnx[%d] removed from pending reconnection queue" , c -> cnx_idx );
21852186 break ;
21862187 }
21872188 }
@@ -2367,7 +2368,7 @@ ngx_http_auth_ldap_init_connections(ngx_cycle_t *cycle)
23672368 server = & ((ngx_http_auth_ldap_server_t * ) halmcf -> servers -> elts )[i ];
23682369 ngx_queue_init (& server -> free_connections );
23692370 ngx_queue_init (& server -> waiting_requests );
2370- ngx_queue_init (& server -> pending_connections );
2371+ ngx_queue_init (& server -> pending_reconnections );
23712372 if (server -> connections <= 1 ) {
23722373 server -> connections = 1 ;
23732374 }
@@ -2506,11 +2507,13 @@ ngx_http_auth_ldap_authenticate(ngx_http_request_t *r, ngx_http_auth_ldap_ctx_t
25062507 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "ngx_http_auth_ldap_authenticate: Authentication timed out" );
25072508 if (ctx -> c != NULL ) {
25082509 if (ctx -> server && ctx -> server -> clean_on_timeout ) {
2509- // In case of LDAP send timeout, imediately close and reconnect the connection
2510+ // Authentication response timeouted => Close and clean the corresponding LDAP connection
25102511 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
2511- "ngx_http_auth_ldap_authenticate: Close/reconnect timeouted Cnx[%d]" , ctx -> c -> cnx_idx );
2512- ngx_http_auth_ldap_close_connection (ctx -> c );
2513- ngx_http_auth_ldap_reconnect_from_connection (ctx -> c );
2512+ "ngx_http_auth_ldap_authenticate: Close timeouted Cnx[%d]" , ctx -> c -> cnx_idx );
2513+ ngx_http_auth_ldap_close_connection (ctx -> c , 1 );
2514+ // Clean the connection
2515+ ctx -> c -> msgid = -1 ;
2516+ ctx -> c = NULL ;
25142517 } else {
25152518 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
25162519 "ngx_http_auth_ldap_authenticate: Return old timedout Cnx[%d]" , ctx -> c -> cnx_idx );
0 commit comments