Skip to content

Commit 7d721f4

Browse files
authored
Merge pull request #83 from ConductorOne/ggreer/connect-error
If we hit max retries and still error, return an error instead of nil.
2 parents 89bddd0 + a8206cc commit 7d721f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pkg/ldap/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ func isNetworkError(err error) bool {
5050
func (c *Client) getConnection(ctx context.Context, isModify bool, f func(client *ldapConn) error) error {
5151
l := ctxzap.Extract(ctx)
5252

53+
var err error
5354
connectAttempts := 0
5455
for connectAttempts < maxConnectAttempts {
5556
if connectAttempts > 0 {
5657
l.Warn("baton-ldap: retrying connection", zap.Int("attempts", connectAttempts), zap.Int("maxAttempts", maxConnectAttempts))
5758
time.Sleep(time.Duration(connectAttempts) * time.Second)
5859
}
59-
cp, err := c.pool.Acquire(ctx)
60+
var cp *puddle.Resource[*ldapConn]
61+
cp, err = c.pool.Acquire(ctx)
6062
if err != nil {
6163
if isNetworkError(err) {
6264
l.Warn("baton-ldap: network error acquiring connection. retrying", zap.Error(err), zap.Int("attempts", connectAttempts), zap.Int("maxAttempts", maxConnectAttempts))
@@ -99,7 +101,7 @@ func (c *Client) getConnection(ctx context.Context, isModify bool, f func(client
99101
cp.Release()
100102
break
101103
}
102-
return nil
104+
return err
103105
}
104106

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

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

0 commit comments

Comments
 (0)