Repository navigation
lib/dialer: Try dialing without reuse in parallel (fixes #6892) - #6893
Conversation
imsodin
left a comment
There was a problem hiding this comment.
The whole "dial two at the same time, close some channels and check some errors to pick one" logic looks pretty much the same as in dialContextWithFallback. Thus I'd separate that into a utility function taking any two addresses/dialers/dialfuncs and returning one (or even any number and return the first in order that succeeded).
| Control: ReusePortControl, | ||
| LocalAddr: laddr, | ||
| } | ||
| reuseConn, reuseErr = dialContextWithFallback(ctx, dialer, network, addr) |
There was a problem hiding this comment.
Earlier you checked the proxy env var already, so this will be a direct dial so might as well do that directly.
|
This is not super pretty imho as it triggers a weird warning (though INFO level) on every connection... |
|
wut, it shouldn't. This should end up being a single connection in lib/connections |
|
I'm sure it does, but on the receiving side it's two connections, one of which gets dropped during the TLS handshake... |
|
Right, I guess we could do it sequentially, rather than in parallel, but we'd potentially double the timeout. Alternatively, we could not log failed TLS handshakes (as it might as well be a port scan etc), but it's sometimes useful to observe when firewall gets in the way. |
Wouldn't the connection not even get through to the listener when a firewall gets in the way, i.e. it never comes to the tls handshake? |
|
I've seen cases where the tcp handshake passes, then the firewall notices it's TLS by checking the first few bytes, and blocks it, because potentially it can't eavesdrop as it's configured. This is obviously in a commercial setting, but never the less a good indicator of what's happening. |
| l.Debugf("Dialing %s result %s %s: %v %v", firstName, network, address, firstConn, firstErr) | ||
| close(firstDone) | ||
| }() | ||
| go func() { |
There was a problem hiding this comment.
Could we add a small delay here, like 1/3 the timeout or such, in the hope that in the normal case we never even get to the point of doing the second dial?
There was a problem hiding this comment.
It will be a bit ugly having to reach into the context to get the deadline, but sure.
There was a problem hiding this comment.
Well I mean a hardcoded 500ms would go a long way as well I think
| }() | ||
| go func() { | ||
| time.Sleep(sleep) | ||
| secondConn, secondErr = second(ctx, network, address) |
There was a problem hiding this comment.
Are we relying on that first succeeding will cause return and context cancellation and second then aborting early here? Otherwise I'd expect the sleep to be a select on ctx, firstDone, time.After so that we don't enter second if first succeeds
There was a problem hiding this comment.
firstDone can also be closed if it fails, so selecting on that doesn't really tell us if we should proceed or not.
Trying to come up with logic that covers this, but it's pretty hairy.
| case <-firstDone: | ||
| if firstErr == nil { | ||
| // First succeeded, no point doing anything in second | ||
| close(secondDone) |
There was a problem hiding this comment.
Should we set secondErr = errors.New("didn't dial") or something just in case? Otherwise LGTM
* main: (368 commits) build: We now target Go 1.14 lib/fs: Disable ioctl on ppc (fixes syncthing#6898) (syncthing#6901) gui, man, authors: Update docs, translations, and contributors lib/dialer: Try dialing without reuse in parallel (fixes syncthing#6892) (syncthing#6893) cmd/stcrashreceiver: Don't crash on nil err all: Remove need to restart syncthing (syncthing#6883) lib/db: Don't put truncated files (ref syncthing#6855, ref syncthing#6501) (syncthing#6888) lib/osutil: Check returned error instead of info (ref syncthing#6885) (syncthing#6887) gui, man, authors: Update docs, translations, and contributors lib/osutil: Preserve perms in AtomicWriter (fixes #tbd) (syncthing#6885) lib/fs: Fix WatchRename test for FreeBSD (fixes syncthing#6613) lib/fs: Unwrap mtimeFile, get fd the "correct" way (ref syncthing#6875) (syncthing#6877) lib/model: Don't close file early (fixes syncthing#6875) (syncthing#6876) lib/fs: Unwrap mtimeFile, get fd the "correct" way (ref syncthing#6875) (syncthing#6877) gui, man, authors: Update docs, translations, and contributors lib/fs: Fix WatchRename test for FreeBSD (fixes syncthing#6613) lib/model: Don't close file early (fixes syncthing#6875) (syncthing#6876) lib/db: Log context on panic (syncthing#6872) gui: Don't show pull order on SO folders (ref syncthing#6807) (syncthing#6871) lib/model: Check folder error before sync-waiting (fixes syncthing#6793) (syncthing#6847) ...
Reusing the listen address influences the routing decision, which is not what we want in some cases.