Skip to content

Conversation

myleshorton
Copy link
Contributor

@myleshorton myleshorton commented Apr 14, 2025

This first always tries to dial directly using proxyless if we can.

@myleshorton myleshorton requested a review from Copilot April 14, 2025 18:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • go.mod: Language not supported

myleshorton and others added 2 commits April 14, 2025 12:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@myleshorton myleshorton marked this pull request as draft April 14, 2025 19:10
@myleshorton
Copy link
Contributor Author

Gotta fix one quirk with the outline stuff.

Comment on lines 46 to 50
configBytes, err := embedFS.ReadFile("smart_dialer_config.yml")
if err != nil {
log.Errorf("Failed to read smart dialer config: %v", err)
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to load this file once instead of reading every dial, so we could move this to newProxylessDialer and add a attribute for config on proxylessDialer

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it would be interesting to have a map of proxyless techniques per country and maybe provide them at the global config, but for now this is good

Copy link
Contributor

Choose a reason for hiding this comment

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

@myleshorton what do you think about adding the smart dialer config as part of the global config? We could add different techniques later and it wouldn't be hard-coded

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid that users in the future might stop updating on this version (by any random reason which happens) and the techniques implemented here would be frozen

@myleshorton myleshorton marked this pull request as ready for review April 14, 2025 19:49
Comment on lines 43 to 53
var addr string
var host string
var port string
var err error
if host, port, err = net.SplitHostPort(address); err != nil {
addr = fmt.Sprintf("%s:%s", host, "443")
} else if port == "" || port == "443" {
addr = fmt.Sprintf("%s:%s", host, "443")
} else {
return nil, fmt.Errorf("proxyless can only dial 443: %s", addr)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really important but, this can all be simplified to:

host, port, _ := net.SplitHostPort(address)
if port != "" && port != "443" {
	return nil, fmt.Errorf("proxyless can only dial 443: %s", addr)
}
addr := host + ":443"

Copy link
Contributor

@garmr-ulfr garmr-ulfr left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, but otherwise LGTM!

}

domains := []string{host}
dialer, err := d.strategyFinder.NewDialer(context.Background(), domains, d.configBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also use the provided ctx here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes!

@myleshorton
Copy link
Contributor Author

I'm taking another pass at this to parallelize it...will have it in tomorrow!

@myleshorton myleshorton marked this pull request as draft April 15, 2025 01:01
@myleshorton myleshorton requested a review from Copilot April 16, 2025 18:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the dialing logic to prioritize direct dialing via proxyless connections while maintaining fallbacks using a parallel dialer approach. Key changes include removing the two-phase dialer implementation, introducing a new smart dialer configuration file, and updating various dialer and client components to integrate the new approach.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dialer/two_phase_dialer.go Removed obsolete two-phase dialer implementation
dialer/smart_dialer_config.yml Added new configuration for smart/proxyless dialing
dialer/proxyless.go Introduced proxylessDialer with enhanced error handling and reset
dialer/parallel_dialer.go Added a parallel dialer that chooses between proxyless and fallback
dialer/fastconnect.go Updated cancellation logging in parallelDial routine
dialer/dialer.go Refactored dialer creation to prioritize direct dialing
dialer/bandit.go Minor update to error messaging in bandit dialer
client/client_test.go Adjusted error message expectations in tests
client/client.go Improved cancellation logging for dial contexts
.github/workflows/go.yml Updated test workflow to remove deprecated reporter usage
Files not reviewed (1)
  • go.mod: Language not supported
Comments suppressed due to low confidence (1)

dialer/dialer.go:49

  • [nitpick] The variable name 'pd' is ambiguous; consider renaming it to 'parallelDialer' to improve clarity.
pd := newParallelPreferProxyless(pdialer, fcd)

@myleshorton myleshorton marked this pull request as ready for review April 16, 2025 18:37
with:
go-version-file: "go.mod"
- name: Install go go-ctrf-json-reporter
run: go install github.com/ctrf-io/go-ctrf-json-reporter/cmd/go-ctrf-json-reporter@latest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

They updated this repo/GH action, so this started failing.

@myleshorton myleshorton changed the title Always try to dial directly first Dial using proxyless in parallel with proxies Apr 16, 2025
@myleshorton
Copy link
Contributor Author

Hey @WendelHime and @garmr-ulfr I ended up making a bunch of changes here to try proxyless in parallel to make sure this only improves upon the current situation for users. I ended up giving the proxyless dialers their own context because otherwise the context from the proxied dialer would cancel the proxyless whenever it succeeded first.

@garmr-ulfr
Copy link
Contributor

Reviewing now

@myleshorton
Copy link
Contributor Author

I just realized I think I lost track of the state change in there -- i.e. FastConnect has the logic to switch to the Bandit, but Bandit doesn't actually get used I don't think! Will fix!

require.NoError(t, err)
resp, err := roundTrip(client, req)
require.Contains(t, err.Error(), "deadline")
require.Contains(t, err.Error(), "any dialers")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is error non-nil on success?

if err != nil {
errCh <- err
}
connCh <- conn
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be wrapped in an else. Currently, it still sends a value (nil) on error and so the following select statement will sometimes read from connCh, instead of errCh, returning nil,nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh good catch!!

@myleshorton myleshorton requested a review from Copilot April 17, 2025 17:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the dialing logic to always attempt a direct proxyless connection first before falling back to traditional proxied dialing. Key changes include:

  • Removal of the two-phase dialer implementation.
  • Introduction of a dedicated proxyless dialer and corresponding configuration.
  • Updates to fast connect, parallel dialer, and client initialization to support the new proxyless-first approach.

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dialer/two_phase_dialer.go Removed obsolete two-phase dialing logic.
dialer/smart_dialer_config.yml Added configuration for smart/proxyless dialing.
dialer/proxyless_test.go Added tests for proxyless dialer behavior.
dialer/proxyless.go Introduced proxyless dialer implementation with error handling.
dialer/parallel_dialer.go Added parallel dialing combining proxyless and default dialers.
dialer/fastconnect_test.go Updated tests to match refactored fast connect dialer signature.
dialer/fastconnect.go Modified fast connect dialer initialization and dialer switch logic.
dialer/dialer.go Updated dialer initialization to use the new proxyless dialer.
dialer/bandit.go Adjusted bandit dialer options to align with the new proxyless strategy.
client/client_test.go Updated expectations to reflect the revised error message wording.
client/client.go Modified client dialer integration and improved context cancellation.
.github/workflows/go.yml Simplified the Go workflow by removing extra test report steps.
Files not reviewed (1)
  • go.mod: Language not supported

@myleshorton myleshorton requested a review from Copilot April 17, 2025 19:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • go.mod: Language not supported

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@myleshorton myleshorton merged commit 99d66de into main Apr 17, 2025
3 checks passed
@myleshorton myleshorton deleted the myles/proxyless branch April 17, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants