Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: create Happy Eyeballs dialer #176
feat: create Happy Eyeballs dialer #176
Changes from 13 commits
3ae0bb8
1d333af
22bac5b
62574b6
4496491
0a4b5fb
ce64110
e59c065
0b15a13
74f2ab3
58df38e
6d8ba93
dd3632e
29f849b
57787d8
48e3ae7
f13cf4b
4fddce3
55cdc26
dc1c999
623ba3d
2580371
c0602e6
e941cab
12d6105
26a786f
52842bb
7fe0ec9
34209a9
de32e39
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
nit it seems this is the only place
newClosedChan()
is used. Maybe we can simplifyclose
the channel here and deletenewClosedChan
function to save some lines?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.
Your code doesn't work because
attemptDelayCh
must be of type<-chan struct{}
, notchan struct{}
, otherwise the assignmentattemptDelayCh = waitCtx.Done()
doesn't compile.Instead of creating a channel, closing, and then assigning to
attemptDelayCh
, I found it better to keep that logic out of the core logic, which is already complicated.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.
SG, maybe
var attemptDelayCh <-chan struct{} = make(chan struct{})
would work here?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.
I tried that too 😅
The problem is that you can't close a read-only channel.
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.
Can these lines be simplified with the following? Because we already have a
case <-searchCtx.Done()
statement in theselect
below, which will be triggered oncesearchCtx
is cancelled. In addition, if we linkedsearchCtx
toreadyToDialCh
, will there be any potential race conditions, because bothcase <-searchCtx.Done()
andcase <-readyToDialCh
will be ready whensearchCtx
is cancelled?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.
I'm assuming you meant
time.NewTimer(50*time.Milisecond).C
. I wasn't sure if we needed to drain theTimer.C
channel, but it seems it's buffered and we don't need to?In any case, I tried based on your suggestion, but the type of channel is different (
<-chan time.Time
), so it requires more changes, not really simpler. Also, the timer sends the time once, versus a context closes the channel, which is easier to reason about (a read will never block).Another important point is that I still need to stop the timer, so I need to pass it to the goroutine to call Stop in case the dial returns before the timer triggers.
On the race condition, that's a valid point. A cancellation will potentially trigger an extra dial. I tried different ways to trigger, but couldn't. In any case, I changed the code to use the background context instead.