diff --git a/client/pool.go b/client/pool.go index 5437f35..96c97a3 100644 --- a/client/pool.go +++ b/client/pool.go @@ -36,19 +36,19 @@ func connPoolWatchdog(serverAddress string, maxPoolSize int, scene *core.Node) { for { - removed := 0 // Check status of existing open connections in pool - for i, dial := range dials { + i := 0 // output index + for _, dial := range dials { if !isConnUp(dial.Connection) { // TBD: this should be moved to check before first write to the socket file descriptor instead of polling here log.Printf("closing bad idle connection and removing from pool - %s", dial.Connection.LocalAddr().String()) dial.Connection.Close() - removeCompleted := scene.Remove(dial.Mesh) - log.Printf("removed: %v", removeCompleted) - - dials = append(dials[:i-removed], dials[i-removed+1:]...) - removed++ + scene.Remove(dial.Mesh) + continue } + dials[i] = dial + i++ } + dials = dials[:i] // fill any empty slots in the pool with fresh connections for poolSize := len(dials); poolSize < maxPoolSize; poolSize++ {