Repository navigation
feat: [OCISDEV-1032] ldap config and retry policy - #12672
Conversation
|
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
bae8f85 to
36f1371
Compare
# Conflicts: # go.mod # go.sum # services/graph/pkg/service/v0/service.go # vendor/github.com/owncloud/reva/v2/pkg/utils/ldap.go # vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/config.go # vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/pool.go # vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/reconnect.go # vendor/modules.txt
36f1371 to
54d8b76
Compare
Code reviewFound 3 issues:
ocis/vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/reconnect.go Lines 104 to 112 in 54d8b76
ocis/services/graph/pkg/config/config.go Lines 66 to 68 in 54d8b76
ocis/vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/pool.go Lines 169 to 172 in 54d8b76 Verified as non-issues: the vendored reva matches upstream commit 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
There was a problem hiding this comment.
Claim
NewWritePolicy's retryable set can never match a real error, so no write is ever retried.
This is a behavioural regression against the retry() function the PR replaces, and it
contradicts the ticket's own acceptance criteria.
Where
vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/reconnect.go:104-112
(upstream: pkg/utils/ldap/reconnect.go in owncloud/reva)
isRetryable: func(code uint16) bool {
switch code {
case ldap.LDAPResultServerDown, // 81
ldap.LDAPResultConnectError: // 91
return true
}
return false
},ErrorNetwork (200) is deliberately excluded, with this rationale in the doc comment:
ErrorNetwork is deliberately NOT retryable for writes: go-ldap's Add/Modify/Del send the
request packet (doRequest) and then read the response (readPacket), so a connection drop
during the response read surfaces as ErrorNetwork AFTER the mutation was already
transmitted. Retrying such a write would double-apply it.
Why it's wrong
-
Codes 81 and 91 are never produced by the go-ldap client. They are declared in
error.goand never passed toNewError()anywhere in the library. Every connection
failure go-ldap raises isErrorNetwork(200) — 27 construction sites. -
So the write policy matches nothing.
isRetryablereturnsfalsefor every error a
write can actually observe. The write branch ofRetryOpis unreachable code. -
This is a regression, not a no-op. The removed
retry()gated on
ldap.IsErrorWithCode(err, ldap.ErrorNetwork)and applied to all operations, including
Add/Del/Modify/ModifyDN.ConnWithReconnectexists precisely because the single
long-lived connection goes stale (idle timeout, LB/firewall reaping) — the comment on
ConnPool.doinpool.gosays exactly that. Before this PR a write on a reaped
connection reconnected and succeeded; now it fails to the caller. -
The double-apply rationale is real but over-broad. Not all
ErrorNetworkis
post-transmit.sendMessageWithFlags(conn.go:462, returning atconn.go:464and
conn.go:497) returnsNewError(ErrorNetwork, "ldap: connection closed")before the
request packet is ever handed to the write loop, andDialURL(conn.go:266,
conn.go:279) wraps dial/TLS failures the same way. Those provably never reached the
server and are safe to retry. (Line numbers are for go-ldap v3.4.14, the version
vendored onstable-8.0.) -
It contradicts the acceptance criteria. OCISDEV-1032 states for writes:
Retry only on connection-establishment failures where the request provably never
reached the server:ErrorNetwork(200),LDAPResultServerDown(81),
LDAPResultConnectError(91).The implementation drops the only one of those three that actually occurs.
Failure scenario
- oCIS runs with the default
ConnWithReconnectpath (OCIS_LDAP_POOL_ENABLED=false). - The LDAP connection sits idle long enough to be reaped by an idle timeout, load
balancer, or firewall. - A user-management write arrives — e.g.
PATCH /graph/v1.0/users/{id}, which reaches
conn.Modify. - go-ldap fails the operation with
ErrorNetwork(200). NewWritePolicy.isRetryable(200)→false.RetryOpbreaks immediately, without
reconnecting.- The write fails and the error surfaces to the API caller. Pre-PR, step 5 reconnected and
the retry succeeded.
Note the read path is unaffected — NewReadPolicy includes ErrorNetwork, so Search
still recovers from a stale connection. The failure is write-only, which makes it easy to
miss in smoke tests that mostly read.
Suggested fix
Distinguish pre-transmit from mid-operation ErrorNetwork rather than excluding 200
wholesale. Options, roughly in order of preference:
- Retry writes when the connection was known-unusable before the request was sent. The
cheap version: checkconn.IsClosing()/ attempt a fresh connection and only retry the
write if the previous attempt never got as far as sending. go-ldap distinguishes these
cases by error message but not by code, so this needs care. - Treat the first write attempt on a checked-out-but-idle connection as retryable by
proactively validating the connection before use (anldap.Compareor abandoned no-op),
keepingErrorNetworknon-retryable after a real send. - At minimum, drop 81/91 from the write set (they are dead) and document plainly that
writes are never retried, so the config's "Applies to both read and write operations"
description stops over-promising. This keeps the safety property but makes the regression
explicit and reviewable.
Also worth adding a test that asserts the write policy matches at least one code the
client can actually emit — the existing "write does not retry ErrorNetwork" test locks
in the current behaviour without checking that anything remains retryable.
Reproduce
./confirm-issue-1.shSee confirm-issue-1.sh in this directory. It performs two independent checks:
- Static: enumerates every
NewError(<Code>site in the vendored go-ldap and shows
that 81/91 appear only as declarations inerror.go, never as constructed errors. - Dynamic: builds a small program against the real
github.com/go-ldap/ldap/v3that
(a) replays the PR's exactisRetryablepredicates over both policies, and (b) forces a
genuine failure by writing to a closed connection and to an unreachable port, printing
the actual result code and whether the write policy would retry it.
The script exits 0 only when both checks confirm the issue. No LDAP server is required — it
builds a real TCP pair and closes the client side to model an idle-reaped connection.
Recorded output (go-ldap v3.4.14, run 2026-07-30)
[static] Every result code the client passes to NewError(), by frequency:
27 ErrorNetwork
14 ErrorFilterCompile
3 ErrorEmptyPassword
2 ErrorDebugging
1 resultCode
1 ErrorUnexpectedResponse
1 ErrorFilterDecompile
Codes: ErrorNetwork=200 ServerDown=81 ConnectError=91 Timeout=85 LocalError=82 Other=80
=== A. Write on a CLOSED connection (models an idle-reaped conn) ===
conn.Modify (write) err=LDAP Result Code 200 "Network Error": ldap: connection closed
code=200 (Network Error)
write-retry(new)=false read-retry(new)=true retry(old, pre-PR)=true
conn.Add (write) ... write-retry(new)=false read-retry(new)=true retry(old, pre-PR)=true
conn.Del (write) ... write-retry(new)=false read-retry(new)=true retry(old, pre-PR)=true
=== B. Dial an unreachable port (connection-establishment failure) ===
ldap.DialURL err=LDAP Result Code 200 "Network Error": dial tcp 127.0.0.1:1: connect: connection refused
code=200 (Network Error)
write-retry(new)=false read-retry(new)=true retry(old, pre-PR)=true
CONFIRMED: NewWritePolicy.isRetryable is unreachable for client-observed errors
=> writes are never retried. Pre-PR retry() returned true for the same errors => regression.
The retry(old, pre-PR)=true column is the regression: every one of these errors was
retried before this PR and is not retried after it. The read-retry(new)=true column shows
why the failure is write-only and easy to miss in read-heavy smoke tests.
* feat: ldap config and retry policy Co-authored-by: Roman Perekhod <[email protected]> ^ Conflicts: ^ go.mod ^ go.sum ^ services/graph/pkg/identity/ldap.go ^ services/graph/pkg/identity/ldap_education_class.go ^ services/graph/pkg/identity/ldap_education_class_test.go ^ services/graph/pkg/identity/ldap_education_school.go ^ services/graph/pkg/identity/ldap_education_school_test.go ^ services/graph/pkg/identity/ldap_education_user.go ^ services/graph/pkg/identity/ldap_education_user_test.go ^ services/graph/pkg/identity/ldap_group.go ^ services/graph/pkg/identity/ldap_writeback.go ^ services/graph/pkg/identity/ldap_writeback_test.go ^ services/graph/pkg/service/v0/service.go ^ vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/config.go ^ vendor/modules.txt
#12710) feat: [OCISDEV-1032] ldap config and retry policy (#12672) * feat: ldap config and retry policy Co-authored-by: Roman Perekhod <[email protected]> ^ Conflicts: ^ go.mod ^ go.sum ^ services/graph/pkg/identity/ldap.go ^ services/graph/pkg/identity/ldap_education_class.go ^ services/graph/pkg/identity/ldap_education_class_test.go ^ services/graph/pkg/identity/ldap_education_school.go ^ services/graph/pkg/identity/ldap_education_school_test.go ^ services/graph/pkg/identity/ldap_education_user.go ^ services/graph/pkg/identity/ldap_education_user_test.go ^ services/graph/pkg/identity/ldap_group.go ^ services/graph/pkg/identity/ldap_writeback.go ^ services/graph/pkg/identity/ldap_writeback_test.go ^ services/graph/pkg/service/v0/service.go ^ vendor/github.com/owncloud/reva/v2/pkg/utils/ldap/config.go ^ vendor/modules.txt
* feat: ldap config and retry policy Co-authored-by: Roman Perekhod <[email protected]> # Conflicts: # go.mod # go.sum # services/graph/pkg/config/config.go # services/graph/pkg/service/v0/service.go # vendor/modules.txt # Conflicts: # services/graph/pkg/service/v0/service.go
* feat: ldap config and retry policy Co-authored-by: Roman Perekhod <[email protected]> # Conflicts: # go.mod # go.sum # services/graph/pkg/config/config.go # services/graph/pkg/service/v0/service.go # vendor/modules.txt # Conflicts: # services/graph/pkg/service/v0/service.go
* feat: [OCISDEV-1032] ldap config and retry policy (#12672) * feat: ldap config and retry policy Co-authored-by: Roman Perekhod <[email protected]> # Conflicts: # go.mod # go.sum # services/graph/pkg/config/config.go # services/graph/pkg/service/v0/service.go # vendor/modules.txt # Conflicts: # services/graph/pkg/service/v0/service.go * test: e2e ldap # Conflicts: # .github/workflows/acceptance-tests.yml # Conflicts: # .github/workflows/acceptance-tests.yml * test: e2e ldap distributed # Conflicts: # .github/workflows/acceptance-tests.yml * fix: post rebases build error
Description
Related to PRs
owncloud/reva#678
owncloud/reva#673
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: