Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #224 from DataDog/leo/fixraceleasecnt
Browse files Browse the repository at this point in the history
[listener/race] fix conn lease data race bug
  • Loading branch information
LeoCavaille authored Feb 6, 2017
2 parents 6089dd4 + 1fcf5a5 commit 112b045
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions agent/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewStoppableListener(l net.Listener, exit chan struct{}, conns int) (*Stopp
func (sl *StoppableListener) Refresh(conns int) {
for range time.Tick(30 * time.Second) {
atomic.StoreInt32(&sl.connLease, int32(conns))
log.Debugf("Refreshed the connection lease: %d conns available", sl.connLease)
log.Debugf("Refreshed the connection lease: %d conns available", conns)
}
}

Expand All @@ -52,7 +52,7 @@ func (e *RateLimitedError) Timeout() bool { return false }

// Accept reimplements the regular Accept but adds a check on the exit channel and returns if needed
func (sl *StoppableListener) Accept() (net.Conn, error) {
if sl.connLease <= 0 {
if atomic.LoadInt32(&sl.connLease) <= 0 {
// we've reached our cap for this lease period, reject the request
return nil, &RateLimitedError{}
}
Expand Down

0 comments on commit 112b045

Please sign in to comment.