in elastictransport/connection.go [170:217]
func (cp *statusConnectionPool) OnFailure(c *Connection) error {
cp.Lock()
defer cp.Unlock()
c.Lock()
if c.IsDead {
if debugLogger != nil {
debugLogger.Logf("Already removed %s\n", c.URL)
}
c.Unlock()
return nil
}
if debugLogger != nil {
debugLogger.Logf("Removing %s...\n", c.URL)
}
c.markAsDead()
cp.scheduleResurrect(c)
c.Unlock()
// Check if connection exists in the list, return error if not.
index := -1
for i, conn := range cp.live {
if conn == c {
index = i
}
}
if index < 0 {
return errors.New("connection not in live list")
}
// Push item to dead list and sort slice by number of failures
cp.dead = append(cp.dead, c)
sort.Slice(cp.dead, func(i, j int) bool {
c1 := cp.dead[i]
c2 := cp.dead[j]
res := c1.Failures > c2.Failures
return res
})
// Remove item; https://github.com/golang/go/wiki/SliceTricks
copy(cp.live[index:], cp.live[index+1:])
cp.live = cp.live[:len(cp.live)-1]
return nil
}