Discount dial errors that won't affect connection tracking

This will reduce pressure on the conntrack instance.
This commit is contained in:
Matt Joiner 2018-11-28 10:32:08 +11:00
parent d9e1ebde70
commit d9fe3f50d3
1 changed files with 9 additions and 1 deletions

View File

@ -530,7 +530,11 @@ func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult {
countDialResult(err)
dr := dialResult{c, network}
if c == nil {
cte.Done()
if err != nil && forgettableDialError(err) {
cte.Forget()
} else {
cte.Done()
}
} else {
dr.Conn = closeWrapper{c, func() error {
err := c.Close()
@ -567,6 +571,10 @@ func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult {
return res
}
func forgettableDialError(err error) bool {
return strings.Contains(err.Error(), "no suitable address found")
}
func (cl *Client) noLongerHalfOpen(t *Torrent, addr string) {
if _, ok := t.halfOpen[addr]; !ok {
panic("invariant broken")