mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Merge pull request #93 from LD-Reborn/79-bug-ioexception-unable-to-read-data-from-the-transport-connection-connection-reset-by-peer
79 bug ioexception unable to read data from the transport connection connection reset by peer
This commit is contained in:
@@ -13,4 +13,5 @@ public class LdapConfig
|
||||
public string UsersOu { get; set; } = "ou=users";
|
||||
public string GroupsOu { get; set; } = "ou=groups";
|
||||
public string MigrationsOu { get; set; } = "ou=migrations";
|
||||
public int ConnectionRetryCount { get; set; } = 10;
|
||||
}
|
||||
@@ -23,21 +23,39 @@ public partial class LdapService : IDisposable
|
||||
|
||||
private async Task ConnectAndBind()
|
||||
{
|
||||
if (!_conn.Connected)
|
||||
int retries = 0;
|
||||
while (retries++ < _opts.ConnectionRetryCount)
|
||||
{
|
||||
Console.WriteLine(_opts.Host);
|
||||
Console.WriteLine(_opts.Port);
|
||||
try
|
||||
{
|
||||
await _conn.ConnectAsync(_opts.Host, _opts.Port);
|
||||
if (!_conn.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _conn.ConnectAsync(_opts.Host, _opts.Port);
|
||||
}
|
||||
catch (SystemException ex)
|
||||
{
|
||||
_logger.LogWarning("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
await _conn.BindAsync(_opts.BindDn, _opts.BindPassword);
|
||||
return;
|
||||
}
|
||||
catch (SystemException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||
throw;
|
||||
if (retries == _opts.ConnectionRetryCount)
|
||||
{
|
||||
_logger.LogError("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||
throw;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||
}
|
||||
}
|
||||
}
|
||||
await _conn.BindAsync(_opts.BindDn, _opts.BindPassword);
|
||||
}
|
||||
|
||||
public string AssetsBaseDn => string.IsNullOrEmpty(_opts.AssetsOu) ? _opts.BaseDn : $"{_opts.AssetsOu},{_opts.BaseDn}";
|
||||
|
||||
Reference in New Issue
Block a user