-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🐛 fix(proxy): eliminate data race in DialContext #12778
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
base: main
Are you sure you want to change the base?
Conversation
Welcome @3mbe! |
Hi @3mbe. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Output of tests with ==================
WARNING: DATA RACE
Write at 0x00c000b9d988 by goroutine 266:
k8s.io/apimachinery/pkg/util/httpstream/spdy.(*SpdyRoundTripper).RoundTrip()
/home/marcos/go/pkg/mod/k8s.io/apimachinery@v0.34.1/pkg/util/httpstream/spdy/roundtripper.go:356 +0x7a4
k8s.io/client-go/transport.(*basicAuthRoundTripper).RoundTrip()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/round_trippers.go:203 +0x401
net/http.send()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:259 +0x8ca
net/http.(*Client).send()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:180 +0x14c
net/http.(*Client).do()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:728 +0x1338
net/http.(*Client).Do()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:587 +0x26a
k8s.io/client-go/transport/spdy.Negotiate()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/spdy/spdy.go:97 +0x255
k8s.io/client-go/transport/spdy.(*dialer).Dial()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/spdy/spdy.go:87 +0x1ea
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContext()
/home/marcos/code/cluster-api/test/infrastructure/inmemory/pkg/server/proxy/dial.go:100 +0x384
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContextWithAddr()
/home/marcos/code/cluster-api/test/infrastructure/inmemory/pkg/server/proxy/dial.go:82 +0x7b
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContextWithAddr-fm()
<autogenerated>:1 +0x1f
google.golang.org/grpc/internal/transport.dial()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/transport/http2_client.go:176 +0x302
google.golang.org/grpc/internal/transport.NewHTTP2Client()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/transport/http2_client.go:221 +0x1c4
google.golang.org/grpc.(*addrConn).createTransport()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1398 +0x475
google.golang.org/grpc.(*addrConn).tryAllAddrs()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1345 +0x669
google.golang.org/grpc.(*addrConn).resetTransportAndUnlock()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1277 +0x23c
google.golang.org/grpc.(*addrConn).connect()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:933 +0x224
google.golang.org/grpc.(*acBalancerWrapper).Connect.gowrap1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:354 +0x33
Previous write at 0x00c000b9d988 by goroutine 268:
k8s.io/apimachinery/pkg/util/httpstream/spdy.(*SpdyRoundTripper).RoundTrip()
/home/marcos/go/pkg/mod/k8s.io/apimachinery@v0.34.1/pkg/util/httpstream/spdy/roundtripper.go:356 +0x7a4
k8s.io/client-go/transport.(*basicAuthRoundTripper).RoundTrip()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/round_trippers.go:203 +0x401
net/http.send()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:259 +0x8ca
net/http.(*Client).send()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:180 +0x14c
net/http.(*Client).do()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:728 +0x1338
net/http.(*Client).Do()
/home/marcos/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/net/http/client.go:587 +0x26a
k8s.io/client-go/transport/spdy.Negotiate()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/spdy/spdy.go:97 +0x255
k8s.io/client-go/transport/spdy.(*dialer).Dial()
/home/marcos/go/pkg/mod/k8s.io/client-go@v0.34.1/transport/spdy/spdy.go:87 +0x1ea
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContext()
/home/marcos/code/cluster-api/test/infrastructure/inmemory/pkg/server/proxy/dial.go:100 +0x384
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContextWithAddr()
/home/marcos/code/cluster-api/test/infrastructure/inmemory/pkg/server/proxy/dial.go:82 +0x7b
sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server/proxy.(*Dialer).DialContextWithAddr-fm()
<autogenerated>:1 +0x1f
google.golang.org/grpc/internal/transport.dial()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/transport/http2_client.go:176 +0x302
google.golang.org/grpc/internal/transport.NewHTTP2Client()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/transport/http2_client.go:221 +0x1c4
google.golang.org/grpc.(*addrConn).createTransport()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1398 +0x475
google.golang.org/grpc.(*addrConn).tryAllAddrs()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1345 +0x669
google.golang.org/grpc.(*addrConn).resetTransportAndUnlock()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:1277 +0x23c
google.golang.org/grpc.(*addrConn).connect()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/clientconn.go:933 +0x224
google.golang.org/grpc.(*acBalancerWrapper).Connect.gowrap1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:354 +0x33
Goroutine 266 (running) created at:
google.golang.org/grpc.(*acBalancerWrapper).Connect()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:354 +0xa8
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).requestConnectionLocked()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:543 +0x604
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).startFirstPassLocked()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:386 +0x3a4
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:345 +0xfb3
google.golang.org/grpc/internal/balancer/gracefulswitch.(*Balancer).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/balancer/gracefulswitch/gracefulswitch.go:194 +0x2b4
google.golang.org/grpc.(*ccBalancerWrapper).updateClientConnState.func1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:124 +0x3c8
google.golang.org/grpc/internal/grpcsync.(*CallbackSerializer).run()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/grpcsync/callback_serializer.go:94 +0x265
google.golang.org/grpc/internal/grpcsync.NewCallbackSerializer.gowrap1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/grpcsync/callback_serializer.go:52 +0x4f
Goroutine 268 (running) created at:
google.golang.org/grpc.(*acBalancerWrapper).Connect()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:354 +0xa8
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).requestConnectionLocked()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:543 +0x604
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).startFirstPassLocked()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:386 +0x3a4
google.golang.org/grpc/balancer/pickfirst/pickfirstleaf.(*pickfirstBalancer).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/pickfirst/pickfirstleaf/pickfirstleaf.go:345 +0xfb3
google.golang.org/grpc/balancer/endpointsharding.(*balancerWrapper).updateClientConnStateLocked()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/endpointsharding/endpointsharding.go:344 +0xbfa
google.golang.org/grpc/balancer/endpointsharding.(*endpointSharding).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/endpointsharding/endpointsharding.go:150 +0xa95
google.golang.org/grpc/balancer/roundrobin.(*rrBalancer).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer/roundrobin/roundrobin.go:67 +0x194
google.golang.org/grpc/internal/balancer/gracefulswitch.(*Balancer).UpdateClientConnState()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/balancer/gracefulswitch/gracefulswitch.go:194 +0x2b4
google.golang.org/grpc.(*ccBalancerWrapper).updateClientConnState.func1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/balancer_wrapper.go:124 +0x3c8
google.golang.org/grpc/internal/grpcsync.(*CallbackSerializer).run()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/grpcsync/callback_serializer.go:94 +0x265
google.golang.org/grpc/internal/grpcsync.NewCallbackSerializer.gowrap1()
/home/marcos/go/pkg/mod/google.golang.org/grpc@v1.72.3/internal/grpcsync/callback_serializer.go:52 +0x4f
================== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ok-to-test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR does a lot of unecesary refactors in the Go code like renaming variables and changing comments. even if the old names are comments are not clear in some way best to leave them be the way they are and only add a minimal diff showcasing the bug fix.
i suggest you backup your current work and start from scratch pushing only the minimal diff.
ef89b88
to
86df4a7
Compare
Hey @chrischdi @neolit123 Thank you both for your patience and for taking the time to mentor me. I’ve reverted the code back to its original state, keeping only the minimal diff needed for the fix. Please let me know if there’s anything else I can do to help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the update. this is much cleaner.
please keep the commits squashed to 1.
86df4a7
to
ebe3256
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/area test
/lgtm
/assign @chrischdi
@neolit123: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
LGTM label has been added. Git tree hash: 943734d0e5c41772c11480e6c7f046dadb95f57a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last nit from my side.
/assign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm pending Christian's point
ebe3256
to
9633304
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor finding
9633304
to
71b1313
Compare
/lgtm /assign @chrischdi |
LGTM label has been added. Git tree hash: 44a194e3f92aece97ee738bf8b4d113577f4ad6e
|
What this PR does / why we need it:
Fixes a data race in
proxy.DialContext
by creating a new SPDY transport and upgrader on each dial. This avoids shared state across concurrent dials and eliminates-race
failures. While this adds a bit of overhead, the correctness and stability gains are well worth it.How I validated this change:
Ran infrastructure tests with the race detector:
make test-infrastructure TEST_ARGS='-race -count=1 -shuffle=on -v'
All tests passed with no race warnings.
Attached the test log as proof: infra-race.log
Which issue(s) this PR fixes:
Fixes #12767
/area testing
/area provider/infrastructure-in-memory
/kind bug