From: Matt Joiner Date: Tue, 27 Nov 2018 23:32:08 +0000 (+1100) Subject: Discount dial errors that won't affect connection tracking X-Git-Tag: v1.0.0~8 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d9fe3f50d3f17e13bf037fcf0a212bdb769e13dd;p=btrtrc.git Discount dial errors that won't affect connection tracking This will reduce pressure on the conntrack instance. --- diff --git a/client.go b/client.go index 1fa9c2bc..a1cea721 100644 --- a/client.go +++ b/client.go @@ -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")