]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Discount dial errors that won't affect connection tracking
authorMatt Joiner <anacrolix@gmail.com>
Tue, 27 Nov 2018 23:32:08 +0000 (10:32 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 27 Nov 2018 23:32:08 +0000 (10:32 +1100)
This will reduce pressure on the conntrack instance.

client.go

index 1fa9c2bc2950f77840adc708c62c4fd3f901b7de..a1cea721731419895997746325fb7ffe4997d715 100644 (file)
--- 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")