Skip to content

Commit ab6a2b4

Browse files
committed
feat: add a reconnect to the initial ldap connection
1 parent 426eac2 commit ab6a2b4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

internal/service/ldap_service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ func NewLdapService(
6363

6464
_, err := ldap.connect()
6565

66+
// Warn: This will hang the tinyauth startup for a good 45 seconds until it fails
6667
if err != nil {
68+
err = ldap.reconnect(10 * time.Second)
6769
return nil, fmt.Errorf("failed to connect to ldap server: %w", err)
6870
}
6971

@@ -79,7 +81,7 @@ func NewLdapService(
7981
err := ldap.heartbeat()
8082
if err != nil {
8183
ldap.log.App.Warn().Err(err).Msg("LDAP connection heartbeat failed, attempting to reconnect")
82-
if reconnectErr := ldap.reconnect(); reconnectErr != nil {
84+
if reconnectErr := ldap.reconnect(5 * time.Second); reconnectErr != nil {
8385
ldap.log.App.Error().Err(reconnectErr).Msg("Failed to reconnect to LDAP server")
8486
continue
8587
}
@@ -247,11 +249,11 @@ func (ldap *LdapService) heartbeat() error {
247249
return nil
248250
}
249251

250-
func (ldap *LdapService) reconnect() error {
252+
func (ldap *LdapService) reconnect(interval time.Duration) error {
251253
ldap.log.App.Info().Msg("Attempting to reconnect to LDAP server")
252254

253255
exp := backoff.NewExponentialBackOff()
254-
exp.InitialInterval = 500 * time.Millisecond
256+
exp.InitialInterval = interval
255257
exp.RandomizationFactor = 0.1
256258
exp.Multiplier = 1.5
257259
exp.Reset()

0 commit comments

Comments
 (0)