Skip to content

Commit

Permalink
Fix lock problem in server
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens authored and traefiker committed Mar 15, 2019
1 parent f1b085f commit 615ceab
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/server/server_entrypoint_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,20 @@ func (c *connectionTracker) RemoveConnection(conn net.Conn) {
delete(c.conns, conn)
}

func (c *connectionTracker) isEmpty() bool {
c.lock.RLock()
defer c.lock.RUnlock()
return len(c.conns) == 0
}

// Shutdown wait for the connection closing
func (c *connectionTracker) Shutdown(ctx context.Context) error {
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for {
c.lock.RLock()
if len(c.conns) == 0 {
if c.isEmpty() {
return nil
}
c.lock.RUnlock()
select {
case <-ctx.Done():
return ctx.Err()
Expand Down

0 comments on commit 615ceab

Please sign in to comment.