Skip to content

lib/dialer: Try dialing without reuse in parallel (fixes #6892) - #6893

Merged
calmh merged 8 commits into
syncthing:mainfrom
AudriusButkevicius:fix-dial
Aug 18, 2020
Merged

calmh merged 8 commits into
syncthing:mainfrom
AudriusButkevicius:fix-dial

Conversation

@AudriusButkevicius

Copy link
Copy Markdown
Member

Reusing the listen address influences the routing decision, which is not what we want in some cases.

@imsodin imsodin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread lib/dialer/public.go Outdated
Control: ReusePortControl,
LocalAddr: laddr,
}
reuseConn, reuseErr = dialContextWithFallback(ctx, dialer, network, addr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier you checked the proxy env var already, so this will be a direct dial so might as well do that directly.

imsodin
imsodin previously approved these changes Aug 16, 2020
@calmh

calmh commented Aug 17, 2020

Copy link
Copy Markdown
Member

This is not super pretty imho as it triggers a weird warning (though INFO level) on every connection...

[MRIW7] 10:28:57 INFO: Listen (BEP/tcp): TLS handshake: EOF
[MRIW7] 10:28:57 INFO: Established secure connection to ...etc

@AudriusButkevicius

AudriusButkevicius commented Aug 17, 2020 •

Copy link
Copy Markdown
Member Author

wut, it shouldn't. This should end up being a single connection in lib/connections

@calmh

calmh commented Aug 17, 2020

Copy link
Copy Markdown
Member

I'm sure it does, but on the receiving side it's two connections, one of which gets dropped during the TLS handshake...

@AudriusButkevicius

AudriusButkevicius commented Aug 17, 2020 •

Copy link
Copy Markdown
Member Author

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.

@imsodin

imsodin commented Aug 17, 2020

Copy link
Copy Markdown
Member

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?

@AudriusButkevicius

AudriusButkevicius commented Aug 17, 2020 •

Copy link
Copy Markdown
Member Author

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.

Comment thread lib/dialer/public.go
l.Debugf("Dialing %s result %s %s: %v %v", firstName, network, address, firstConn, firstErr)
close(firstDone)
}()
go func() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be a bit ugly having to reach into the context to get the deadline, but sure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I mean a hardcoded 500ms would go a long way as well I think

Comment thread lib/dialer/public.go
}()
go func() {
time.Sleep(sleep)
secondConn, secondErr = second(ctx, network, address)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/dialer/public.go
case <-firstDone:
if firstErr == nil {
// First succeeded, no point doing anything in second
close(secondDone)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set secondErr = errors.New("didn't dial") or something just in case? Otherwise LGTM

@calmh
calmh merged commit d0c6c18 into syncthing:main Aug 18, 2020
@calmh calmh added this to the v1.9.0 milestone Aug 18, 2020
@AudriusButkevicius
AudriusButkevicius deleted the fix-dial branch August 18, 2020 11:17
calmh added a commit to calmh/syncthing that referenced this pull request Aug 19, 2020
* 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)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Aug 19, 2021
@syncthing syncthing locked and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants