Skip to content

Commit

Permalink
upstream: use defer
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jun 9, 2023
1 parent 9b16ffe commit a0b07ac
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions upstream/upstream_dnscrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func (p *dnsCrypt) exchangeDNSCrypt(m *dns.Msg) (resp *dns.Msg, err error) {
func (p *dnsCrypt) resetClient() (client *dnscrypt.Client, ri *dnscrypt.ResolverInfo, err error) {
addr := p.Address()

defer func() {
p.mu.Lock()
defer p.mu.Unlock()

p.client, p.resolverInfo = client, ri
}()

// Use UDP for DNSCrypt upstreams by default.
client = &dnscrypt.Client{Timeout: p.timeout, Net: networkUDP}
ri, err = client.Dial(addr)
Expand All @@ -140,16 +147,5 @@ func (p *dnsCrypt) resetClient() (client *dnscrypt.Client, ri *dnscrypt.Resolver
}
}

func() {
p.mu.Lock()
defer p.mu.Unlock()

// Update the client and server info in an anonymous function to make
// ineffassign do its job.
//
// See https://github.com/gordonklaus/ineffassign/issues/82.
p.client, p.resolverInfo = client, ri
}()

return client, ri, err
}

0 comments on commit a0b07ac

Please sign in to comment.