Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: make conn.UDPSize atomic to pacify -race #14

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"io"
"net"
"strings"
"sync/atomic"
"time"
)

Expand All @@ -33,7 +34,7 @@
// A Conn represents a connection to a DNS server.
type Conn struct {
net.Conn // a net.Conn holding the connection
UDPSize uint16 // minimum receive buffer for UDP messages
UDPSize atomic.Uint32 // minimum receive buffer for UDP messages (actually uint16, but there's no atomic variant)

Check failure on line 37 in client.go

View workflow job for this annotation

GitHub Actions / Build and Test (1.17.x)

undefined: atomic.Uint32

Check failure on line 37 in client.go

View workflow job for this annotation

GitHub Actions / Build and Test (1.18.x)

undefined: atomic.Uint32
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2)
TsigProvider TsigProvider // An implementation of the TsigProvider interface. If defined it replaces TsigSecret and is used for all TSIG operations.
tsigRequestMAC string
Expand Down Expand Up @@ -142,7 +143,7 @@
if err != nil {
return nil, err
}
conn.UDPSize = c.UDPSize
conn.UDPSize.Store(uint32(c.UDPSize))
return conn, nil
}

Expand Down Expand Up @@ -239,11 +240,11 @@
opt := m.IsEdns0()
// If EDNS0 is used use that for size.
if opt != nil && opt.UDPSize() >= MinMsgSize {
co.UDPSize = opt.UDPSize()
co.UDPSize.Store(uint32(opt.UDPSize()))
}
// Otherwise use the client's configured UDP size.
if opt == nil && c.UDPSize >= MinMsgSize {
co.UDPSize = c.UDPSize
co.UDPSize.Store(uint32(c.UDPSize))
}

// write with the appropriate write timeout
Expand Down Expand Up @@ -301,8 +302,8 @@
)

if isPacketConn(co.Conn) {
if co.UDPSize > MinMsgSize {
p = make([]byte, co.UDPSize)
if us := co.UDPSize.Load(); us > MinMsgSize {
p = make([]byte, us)
} else {
p = make([]byte, MinMsgSize)
}
Expand Down Expand Up @@ -436,7 +437,6 @@
// co.WriteMsg(m)
// in, _ := co.ReadMsg()
// co.Close()
//
func ExchangeConn(c net.Conn, m *Msg) (r *Msg, err error) {
println("dns: ExchangeConn: this function is deprecated")
co := new(Conn)
Expand Down
Loading