Skip to content
Snippets Groups Projects
Commit 3e38f41a authored by ale's avatar ale
Browse files

Reconnect on ldap NetworkError

Before, we weren't releasing the connection properly.
parent 31066b08
Branches
No related tags found
No related merge requests found
......@@ -10,19 +10,27 @@ import (
"git.autistici.org/ai3/go-common/clientutil"
)
// Treat all errors as potential network-level issues, except for a
// whitelist of LDAP protocol level errors that we know are benign.
func isTemporaryLDAPError(err error) bool {
ldapErr, ok := err.(*ldap.Error)
if !ok {
return true
// Interface matched by net.Error.
type hasTemporary interface {
Temporary() bool
}
switch ldapErr.ResultCode {
// Treat network errors as temporary. Other errors are permanent by
// default.
func isTemporaryLDAPError(err error) bool {
switch v := err.(type) {
case *ldap.Error:
switch v.ResultCode {
case ldap.ErrorNetwork:
return true
default:
return false
}
case hasTemporary:
return v.Temporary()
default:
return false
}
}
// Search performs the given search request. It will retry the request
......@@ -32,6 +40,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
err := clientutil.Retry(func() error {
conn, err := p.Get(ctx)
if err != nil {
// Here conn is nil, so we don't need to Release it.
if isTemporaryLDAPError(err) {
return clientutil.TempError(err)
}
......@@ -44,7 +53,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
result, err = conn.Search(searchRequest)
if err != nil && isTemporaryLDAPError(err) {
p.Release(conn, nil)
p.Release(conn, err)
return clientutil.TempError(err)
}
p.Release(conn, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment