Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
go-common
Commits
3e38f41a
Commit
3e38f41a
authored
7 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Reconnect on ldap NetworkError
Before, we weren't releasing the connection properly.
parent
31066b08
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ldap/search.go
+19
-10
19 additions, 10 deletions
ldap/search.go
with
19 additions
and
10 deletions
ldap/search.go
+
19
−
10
View file @
3e38f41a
...
@@ -10,16 +10,24 @@ import (
...
@@ -10,16 +10,24 @@ import (
"git.autistici.org/ai3/go-common/clientutil"
"git.autistici.org/ai3/go-common/clientutil"
)
)
// Treat all errors as potential network-level issues, except for a
// Interface matched by net.Error.
// whitelist of LDAP protocol level errors that we know are benign.
type
hasTemporary
interface
{
Temporary
()
bool
}
// Treat network errors as temporary. Other errors are permanent by
// default.
func
isTemporaryLDAPError
(
err
error
)
bool
{
func
isTemporaryLDAPError
(
err
error
)
bool
{
ldapErr
,
ok
:=
err
.
(
*
ldap
.
Error
)
switch
v
:=
err
.
(
type
)
{
if
!
ok
{
case
*
ldap
.
Error
:
return
true
switch
v
.
ResultCode
{
}
case
ldap
.
ErrorNetwork
:
switch
ldapErr
.
ResultCode
{
return
true
case
ldap
.
ErrorNetwork
:
default
:
return
true
return
false
}
case
hasTemporary
:
return
v
.
Temporary
()
default
:
default
:
return
false
return
false
}
}
...
@@ -32,6 +40,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
...
@@ -32,6 +40,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
err
:=
clientutil
.
Retry
(
func
()
error
{
err
:=
clientutil
.
Retry
(
func
()
error
{
conn
,
err
:=
p
.
Get
(
ctx
)
conn
,
err
:=
p
.
Get
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
// Here conn is nil, so we don't need to Release it.
if
isTemporaryLDAPError
(
err
)
{
if
isTemporaryLDAPError
(
err
)
{
return
clientutil
.
TempError
(
err
)
return
clientutil
.
TempError
(
err
)
}
}
...
@@ -44,7 +53,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
...
@@ -44,7 +53,7 @@ func (p *ConnectionPool) Search(ctx context.Context, searchRequest *ldap.SearchR
result
,
err
=
conn
.
Search
(
searchRequest
)
result
,
err
=
conn
.
Search
(
searchRequest
)
if
err
!=
nil
&&
isTemporaryLDAPError
(
err
)
{
if
err
!=
nil
&&
isTemporaryLDAPError
(
err
)
{
p
.
Release
(
conn
,
nil
)
p
.
Release
(
conn
,
err
)
return
clientutil
.
TempError
(
err
)
return
clientutil
.
TempError
(
err
)
}
}
p
.
Release
(
conn
,
err
)
p
.
Release
(
conn
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment