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

Made base transport layer force ipv4 usage if ipv6 is not supported #10485

Closed
wants to merge 1 commit into from

Conversation

melinath
Copy link
Member

@melinath melinath commented Apr 18, 2024

Fixes hashicorp/terraform-provider-google#6782

Workaround for golang/go#25321

Note that while I was able to reproduce the Go issue, I was not able to reproduce the TF issue - there seems to be some amount of randomness in terms of when it presents. However, this seems to be the best option for working around the issue.

This PR also removes a lot of complexity that was previously implicitly part of our transport setup via transport.NewHTTPClient and that was mostly unused. (I traced through the code to boil it down to the 10 or so 6 lines we were actually using.)

yaqs/47302089738551296

Release Note Template for Downstream PRs (will be copied)

provider: Forced HTTP requests to use ipv4 on systems with ipv6 disabled, such as Cloud Shell.

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 47 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 1 file changed, 47 insertions(+), 5 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 3606
Passed tests: 3242
Skipped tests: 364
Affected tests: 0

Click here to see the affected service packages
all service packages are affected

$\textcolor{green}{\textsf{All tests passed!}}$
View the build log

@melinath melinath requested a review from c2thorn April 19, 2024 15:39
@rileykarson rileykarson requested a review from ScottSuarez April 19, 2024 18:14
@rileykarson
Copy link
Member

Adding @ScottSuarez as a mandatory reviewer- we should ensure that MTLS is not broken as a result of this change.

trans := http.DefaultTransport.(*http.Transport).Clone()
// Increase MaxIdleConnsPerHost due to reported performance issues under load in the
// GCS client.
trans.MaxIdleConnsPerHost = 100
Copy link
Member

Choose a reason for hiding this comment

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

If I'm understanding correctly, these tweaks are from here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep!

Copy link
Member

Choose a reason for hiding this comment

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

Great, you did mention it in the comment, but I'll leave the link here just for posterity

// default transport and makes some tweaks to match best practices
// from google-api-go-client, as well as ensuring that IPv6 does
// not get used in environments that don't support it.
func baseTransport() (http.RoundTripper, error) {
Copy link
Member

@c2thorn c2thorn Apr 19, 2024

Choose a reason for hiding this comment

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

I may be missing something here, but why can't we reuse the google-api-go-client's NewClient method and override the given transport's dial context after?

Copy link
Member Author

Choose a reason for hiding this comment

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

http.Client's Transport is a RoundTripper rather than a Transport, so we would need to cast it back to a Transport in order to do that. I don't see a reason that wouldn't work, and that would've been a lot easier to implement.

I think, having dug through the code, I would slightly prefer this way because we know exactly what we're getting and don't have to worry about the intricacies of NewClient.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's reasonable now that we've gone through the code. My only concerns are about missing something, but I've gone through it myself now and everything seems in order.

@c2thorn
Copy link
Member

c2thorn commented Apr 19, 2024

Do we want a provider-wide changelog note?

@melinath
Copy link
Member Author

Do we want a provider-wide changelog note?

added

Copy link
Member

@c2thorn c2thorn left a comment

Choose a reason for hiding this comment

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

LGTM for non-MTLS stuff

@c2thorn
Copy link
Member

c2thorn commented Apr 19, 2024

Do we want a provider-wide changelog note?

added

We are expecting some user-facing impact right? Specifically user's facing hashicorp/terraform-provider-google#6782 will now have their ipv4 settings honored?

@melinath
Copy link
Member Author

melinath commented Apr 19, 2024

Do we want a provider-wide changelog note?

added

We are expecting some user-facing impact right? Specifically user's facing hashicorp/terraform-provider-google#6782 will now have their ipv4 settings honored?

🤦 yep. yep. we sure are. fixed.

Copy link
Contributor

@ScottSuarez ScottSuarez left a comment

Choose a reason for hiding this comment

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

// from google-api-go-client, as well as ensuring that IPv6 does
// not get used in environments that don't support it.
func baseTransport() (http.RoundTripper, error) {
trans := http.DefaultTransport.(*http.Transport).Clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

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

Marking request changes so that we can't click the big green button accidentally

@melinath
Copy link
Member Author

Unfortunately the "just override the transport's dialcontext" approach is not feasible because the base transport is wrapped a few times and two of them use private fields to store the wrapped RoundTripper.

@melinath
Copy link
Member Author

yaqs/5034757202074664960

@melinath
Copy link
Member Author

I'm going to attempt to get this change made in google-api-go-client

@melinath
Copy link
Member Author

Copy link

@melinath, this PR is waiting for action from you. Please address any comments or change requests, or re-request review from a core reviewer if no action is required.

Image showing the re-request review button

If no action is taken, this PR will be closed in 14 days.

This notification can be disabled with the disable-automatic-closure label.

@rileykarson
Copy link
Member

Hey! I'm closing this PR as a part of a cleanup of older inactive PRs, using a threshold of PRs last updated over 3 months ago. This doesn't represent rejection of the change, and feel free to comment for me to reopen it if you plan to pick it back up, or feel free to start a new PR with the same changes in the future.

@rileykarson rileykarson closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform not honouring OS IPv4 settings, using IPv6 dst to call *.googleapis.com
5 participants