Skip to content

Commit

Permalink
close resolver connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Feb 2, 2020
1 parent 694c05b commit f1bad4d
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,12 @@ func (ex *dnsExchanger) Exchange(ctx context.Context, query []byte) ([]byte, err
return nil, err
}
c.SetDeadline(time.Now().Add(ex.options.timeout - time.Since(t)))

mq := &dns.Msg{}
if err = mq.Unpack(query); err != nil {
return nil, err
}
defer c.Close()

conn := &dns.Conn{
Conn: c,
}

if err = conn.WriteMsg(mq); err != nil {
if _, err = conn.Write(query); err != nil {
return nil, err
}

Expand Down Expand Up @@ -683,18 +678,17 @@ func (ex *dnsTCPExchanger) Exchange(ctx context.Context, query []byte) ([]byte,
return nil, err
}
c.SetDeadline(time.Now().Add(ex.options.timeout - time.Since(t)))
defer c.Close()

conn := &dns.Conn{
Conn: c,
}

if _, err = conn.Write(query); err != nil {
return nil, err
}

mr, err := conn.ReadMsg()
if err != nil {
log.Log("[dns] exchange", err)
return nil, err
}

Expand Down Expand Up @@ -753,11 +747,11 @@ func (ex *dotExchanger) Exchange(ctx context.Context, query []byte) ([]byte, err
return nil, err
}
c.SetDeadline(time.Now().Add(ex.options.timeout - time.Since(t)))
defer c.Close()

conn := &dns.Conn{
Conn: c,
}

if _, err = conn.Write(query); err != nil {
return nil, err
}
Expand Down

0 comments on commit f1bad4d

Please sign in to comment.