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
Show 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,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
)
...
...
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