Fix lock problem in server

This commit is contained in:
Julien Salleyron 2019-03-15 10:04:05 +01:00 committed by Traefiker Bot
parent f1b085fa36
commit 615ceab597

View file

@ -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()