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

fix: fix HappyEyeballs test race #320

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 19 additions & 1 deletion transport/happyeyeballs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,26 @@ func TestHappyEyeballsStreamDialer_DialStream(t *testing.T) {
})

t.Run("IP order", func(t *testing.T) {
waitForIPv4Ch := make(chan struct{})
dialFailErr := errors.New("failed to dial")
baseDialer := collectStreamDialer{Dialer: newErrorStreamDialer(dialFailErr)}
baseDialer := collectStreamDialer{Dialer: FuncStreamDialer(func(ctx context.Context, addr string) (StreamConn, error) {
ap, err := netip.ParseAddrPort(addr)
require.NoError(t, err)
if ap.Addr().Is4() {
select {
case <-waitForIPv4Ch:
// Avoids closing a closed channel.
default:
close(waitForIPv4Ch)
}
} else {
// We block IPv6 dials until we have IPv4 results. Otherwise all IPv6 dials may proceed before the IPv4 results
// are processed, resulting on a race condition.
<-waitForIPv4Ch
}
time.Sleep(time.Microsecond)
return nil, dialFailErr
})}
dialer := HappyEyeballsStreamDialer{
Dialer: &baseDialer,
Resolve: NewParallelHappyEyeballsResolveFunc(
Expand Down
Loading