Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goatherd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arw
goatherd
Commits
c5773539
Commit
c5773539
authored
8 years ago
by
Lukas Braun
Browse files
Options
Downloads
Patches
Plain Diff
embed faildelay.lock
parent
ba908c88
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
goatherd.go
+5
-9
5 additions, 9 deletions
goatherd.go
with
5 additions
and
9 deletions
goatherd.go
+
5
−
9
View file @
c5773539
...
@@ -52,12 +52,8 @@ var cfg struct {
...
@@ -52,12 +52,8 @@ var cfg struct {
// protect the _sending of responses_, not database access or anything else.
// protect the _sending of responses_, not database access or anything else.
// The reason is that we want to avoid keeping state for non-existent users and
// The reason is that we want to avoid keeping state for non-existent users and
// only after talking to the database do we know if a user exists.
// only after talking to the database do we know if a user exists.
//
// Access to the map itself is synchronized by faildelay.lock. It is only
// neccessary to grab the lock for writing when a user is inserted into the map
// (i.e first login attempt), otherwise a read lock suffices.
var
faildelay
struct
{
var
faildelay
struct
{
lock
sync
.
RWMutex
sync
.
RWMutex
// protects userlocks
userlocks
map
[
string
]
*
sync
.
Mutex
userlocks
map
[
string
]
*
sync
.
Mutex
}
}
...
@@ -265,20 +261,20 @@ func handle_conn(db *sql.DB, conn net.Conn) {
...
@@ -265,20 +261,20 @@ func handle_conn(db *sql.DB, conn net.Conn) {
log
.
Printf
(
"%v: %v"
,
name
,
result
)
log
.
Printf
(
"%v: %v"
,
name
,
result
)
// name exists, get or create its lock
// name exists, get or create its lock
faildelay
.
lock
.
RLock
()
faildelay
.
RLock
()
delay
,
exists
:=
faildelay
.
userlocks
[
name
]
delay
,
exists
:=
faildelay
.
userlocks
[
name
]
faildelay
.
lock
.
RUnlock
()
faildelay
.
RUnlock
()
if
!
exists
{
if
!
exists
{
debugf
(
"[%v] not yet in faildelay.userlocks"
,
remote
)
debugf
(
"[%v] not yet in faildelay.userlocks"
,
remote
)
// no atomic upgrade with sync.RWMutex, so we have to do the lookup again
// no atomic upgrade with sync.RWMutex, so we have to do the lookup again
faildelay
.
lock
.
Lock
()
faildelay
.
Lock
()
delay
,
exists
=
faildelay
.
userlocks
[
name
]
delay
,
exists
=
faildelay
.
userlocks
[
name
]
if
!
exists
{
if
!
exists
{
delay
=
new
(
sync
.
Mutex
)
delay
=
new
(
sync
.
Mutex
)
faildelay
.
userlocks
[
name
]
=
delay
faildelay
.
userlocks
[
name
]
=
delay
}
}
faildelay
.
lock
.
Unlock
()
faildelay
.
Unlock
()
}
}
delay
.
Lock
()
delay
.
Lock
()
...
...
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