From bc249730aac7a6c89dd1bfb5a2f2436ddba496d3 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 10 Apr 2019 18:27:54 +1000 Subject: [PATCH] Fix segfault on nil conntrack.EntryHandle instance when dialing 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index f8d70372b9..2d2a3fa7ea 100644 --- 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 }