]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix segfault on nil conntrack.EntryHandle instance when dialing v1.1.3
authorMatt Joiner <anacrolix@gmail.com>
Wed, 10 Apr 2019 08:27:54 +0000 (18:27 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 10 Apr 2019 08:27:54 +0000 (18:27 +1000)
Fixes https://github.com/anacrolix/torrent/issues/314. Comments were added to the the conntrack package master, but have no functional change required here.

client.go

index f8d70372b93fa4133ecda1f9a3ab4018c191759c..2d2a3fa7eac4dcdcd6f99668916201cd4e929665 100644 (file)
--- a/client.go
+++ b/client.go
@@ -521,8 +521,13 @@ func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult {
                                                "dial torrent client",
                                                0,
                                        )
+                                       // Try to avoid committing to a dial if the context is complete as it's
+                                       // difficult to determine which dial errors allow us to forget the connection
+                                       // tracking entry handle.
                                        if ctx.Err() != nil {
-                                               cte.Forget()
+                                               if cte != nil {
+                                                       cte.Forget()
+                                               }
                                                resCh <- dialResult{}
                                                return
                                        }