@@ -468,10 +468,7 @@ with_ldap({ok, Creds}, Fun, Servers) ->
468
468
fun () ->
469
469
case with_login (Creds , Servers , Opts , Fun ) of
470
470
{error , {gen_tcp_error , _ }} ->
471
- % % purge and retry with a new connection
472
- rabbit_log :warning (" TCP connection to a LDAP server was closed or otherwise defunct~n " ),
473
- purge_conn (Creds == anon , Servers , Opts ),
474
- rabbit_log :warning (" LDAP will retry with a new connection~n " ),
471
+ purge_connection (Creds , Servers , Opts ),
475
472
with_login (Creds , Servers , Opts , Fun );
476
473
Result -> Result
477
474
end
@@ -480,7 +477,7 @@ with_ldap({ok, Creds}, Fun, Servers) ->
480
477
with_login (Creds , Servers , Opts , Fun ) ->
481
478
with_login (Creds , Servers , Opts , Fun , ? LDAP_OPERATION_RETRIES ).
482
479
with_login (_Creds , _Servers , _Opts , _Fun , 0 = _RetriesLeft ) ->
483
- rabbit_log :warning (" LDAP failed to perform an operation. TCP connection to a LDAP server was closed or otherwise defunct. Exhausted all retries.~n " ),
480
+ rabbit_log :warning (" LDAP failed to perform an operation. TCP connection to a LDAP server was closed or otherwise defunct. Exhausted all retries." ),
484
481
{error , ldap_connect_error };
485
482
with_login (Creds , Servers , Opts , Fun , RetriesLeft ) ->
486
483
case get_or_create_conn (Creds == anon , Servers , Opts ) of
@@ -489,9 +486,10 @@ with_login(Creds, Servers, Opts, Fun, RetriesLeft) ->
489
486
anon ->
490
487
? L1 (" anonymous bind" , []),
491
488
case call_ldap_fun (Fun , LDAP ) of
492
- {error , ldap_closed } ->
493
- with_login (Creds , Servers , Opts , Fun , RetriesLeft - 1 );
494
- Other -> Other
489
+ {error , ldap_closed } ->
490
+ purge_connection (Creds , Servers , Opts ),
491
+ with_login (Creds , Servers , Opts , Fun , RetriesLeft - 1 );
492
+ Other -> Other
495
493
end ;
496
494
{UserDN , Password } ->
497
495
case eldap :simple_bind (LDAP , UserDN , Password ) of
@@ -510,11 +508,13 @@ with_login(Creds, Servers, Opts, Fun, RetriesLeft) ->
510
508
[scrub_dn (UserDN , env (log ))]),
511
509
{refused , UserDN , []};
512
510
{error , ldap_closed } ->
511
+ purge_connection (Creds , Servers , Opts ),
513
512
with_login (Creds , Servers , Opts , Fun , RetriesLeft - 1 );
514
513
{error , {gen_tcp_error , _ }} ->
514
+ purge_connection (Creds , Servers , Opts ),
515
515
with_login (Creds , Servers , Opts , Fun , RetriesLeft - 1 );
516
516
{error , E } ->
517
- ? L1 (" bind error: ~s ~p " ,
517
+ ? L1 (" bind error: ~p ~p " ,
518
518
[scrub_dn (UserDN , env (log )), E ]),
519
519
% % Do not report internal bind error to a client
520
520
{error , ldap_bind_error }
@@ -525,10 +525,16 @@ with_login(Creds, Servers, Opts, Fun, RetriesLeft) ->
525
525
case Error of
526
526
{error , {gen_tcp_error , _ }} -> Error ;
527
527
% % Do not report internal connection error to a client
528
- _Other -> {error , ldap_connect_error }
528
+ _Other -> {error , ldap_connect_error }
529
529
end
530
530
end .
531
531
532
+ purge_connection (Creds , Servers , Opts ) ->
533
+ % % purge and retry with a new connection
534
+ rabbit_log :warning (" TCP connection to a LDAP server was closed or otherwise defunct." ),
535
+ purge_conn (Creds == anon , Servers , Opts ),
536
+ rabbit_log :warning (" LDAP will retry with a new connection." ).
537
+
532
538
call_ldap_fun (Fun , LDAP ) ->
533
539
call_ldap_fun (Fun , LDAP , " " ).
534
540
@@ -617,7 +623,7 @@ purge_conn(IsAnon, Servers, Opts) ->
617
623
Conns = get (ldap_conns ),
618
624
Key = {IsAnon , Servers , Opts },
619
625
{ok , Conn } = maps :find (Key , Conns ),
620
- rabbit_log :warning (" LDAP Purging an already closed LDAP server connection~n " ),
626
+ rabbit_log :warning (" LDAP Purging an already closed LDAP server connection" ),
621
627
% We cannot close the connection with eldap:close/1 because as of OTP-13327
622
628
% eldap will try to do_unbind first and will fail with a `{gen_tcp_error, closed}`.
623
629
% Since we know that the connection is already closed, we just
0 commit comments