Skip to content

Commit

Permalink
Merge pull request #83 from ConductorOne/ggreer/connect-error
Browse files Browse the repository at this point in the history
If we hit max retries and still error, return an error instead of nil.
  • Loading branch information
ggreer authored Nov 20, 2024
2 parents 89bddd0 + a8206cc commit 7d721f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/ldap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ func isNetworkError(err error) bool {
func (c *Client) getConnection(ctx context.Context, isModify bool, f func(client *ldapConn) error) error {
l := ctxzap.Extract(ctx)

var err error
connectAttempts := 0
for connectAttempts < maxConnectAttempts {
if connectAttempts > 0 {
l.Warn("baton-ldap: retrying connection", zap.Int("attempts", connectAttempts), zap.Int("maxAttempts", maxConnectAttempts))
time.Sleep(time.Duration(connectAttempts) * time.Second)
}
cp, err := c.pool.Acquire(ctx)
var cp *puddle.Resource[*ldapConn]
cp, err = c.pool.Acquire(ctx)
if err != nil {
if isNetworkError(err) {
l.Warn("baton-ldap: network error acquiring connection. retrying", zap.Error(err), zap.Int("attempts", connectAttempts), zap.Int("maxAttempts", maxConnectAttempts))
Expand Down Expand Up @@ -99,7 +101,7 @@ func (c *Client) getConnection(ctx context.Context, isModify bool, f func(client
cp.Release()
break
}
return nil
return err
}

func parsePageToken(pageToken string) (string, []byte, error) {
Expand Down Expand Up @@ -172,8 +174,6 @@ func (c *Client) _ldapSearch(ctx context.Context,
var ret []*ldap.Entry
var nextPageToken string

// TODO (ggreer): Reconnecting with a pageToken doesn't work because the ldap cookie is per-connection
// To fix this, we should restart the query with no pageToken
err := c.getConnection(ctx, false, func(client *ldapConn) error {
if pageSize <= 0 {
pageSize = defaultPageSize
Expand Down

0 comments on commit 7d721f4

Please sign in to comment.