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

Conversation

bimmlerd
Copy link
Member

@bimmlerd bimmlerd commented Sep 9, 2024

As is, Conn is not safe to access concurrently, and the race detector correctly identifies occurrences of this, by reporting races in cilium/cilium:

 Read at 0x00c00754eb90 by goroutine 3305340:
   github.com/cilium/dns.(*Conn).ReadMsgHeader()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:304 +0xc4
   github.com/cilium/dns.(*Conn).ReadMsg()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:274 +0x3d
   github.com/cilium/dns.handler.func2()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:173 +0x15a

 Previous write at 0x00c00754eb90 by goroutine 3305339:
   github.com/cilium/dns.(*Client).SendContext()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:242 +0xfe
   github.com/cilium/dns.handler()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:251 +0x773
   github.com/cilium/dns.(*SharedClient).ExchangeSharedContext.gowrap1()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:298 +0x5d

By making the size an atomic uint, the race detector will be pacified.

Related: cilium/cilium#33897

As is, Conn is not safe to access concurrently, and the race detector
correctly identifies occurrences of this, by reporting races in
cilium/cilium:

 Read at 0x00c00754eb90 by goroutine 3305340:
   github.com/cilium/dns.(*Conn).ReadMsgHeader()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:304 +0xc4
   github.com/cilium/dns.(*Conn).ReadMsg()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:274 +0x3d
   github.com/cilium/dns.handler.func2()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:173 +0x15a

 Previous write at 0x00c00754eb90 by goroutine 3305339:
   github.com/cilium/dns.(*Client).SendContext()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/client.go:242 +0xfe
   github.com/cilium/dns.handler()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:251 +0x773
   github.com/cilium/dns.(*SharedClient).ExchangeSharedContext.gowrap1()
       /go/src/github.com/cilium/cilium/vendor/github.com/cilium/dns/shared_client.go:298 +0x5d

By making the size an atomic uint, the race detector will be pacified.

Signed-off-by: David Bimmler <[email protected]>
@christarazi
Copy link
Member

What about other usages of Conn? Surely, not just the UDPSize is accessed concurrently. It feels like this is just one of many moles to whack?

@bimmlerd
Copy link
Member Author

What about other usages of Conn? Surely, not just the UDPSize is accessed concurrently. It feels like this is just one of many moles to whack?

Yeah, I realised this too. Really, the shared client should not be using the dns.Conn concurrently. I'll work on an actual solution to this, which might actually live in cilium/cilium

@bimmlerd bimmlerd closed this Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants