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

Allow reuse of HTTP connection #335

Open
1 task done
nickabousselam opened this issue Oct 23, 2023 · 0 comments
Open
1 task done

Allow reuse of HTTP connection #335

nickabousselam opened this issue Oct 23, 2023 · 0 comments

Comments

@nickabousselam
Copy link

nickabousselam commented Oct 23, 2023

Terraform CLI and Provider Versions

% terraform --version
Terraform v1.5.7
on darwin_arm64

  • provider registry.terraform.io/go-gitea/gitea v0.3.0
  • provider registry.terraform.io/hashicorp/http v3.4.0
  • provider registry.terraform.io/hashicorp/random v3.5.1
  • provider registry.terraform.io/hashicorp/time v0.9.1

Use Cases or Problem Statement

We are using this HTTP provider to make multiple requests to the same API in a single Terraform sync.

We have found that when these requests are made, a new TCP connection is created for each request instead of the connection re-use/pooling that I would typically expect in Go. This causes a problem for us - we unavoidably have to make several hundred requests to that API and the connections limit on the remote server is exhausted as a result of not having connection reuse.

Proposal

The reason for the problem I believe is that the HTTP client transport is being cloned each time in the provider's Read() method instead of relying directly on the default shared transport http.DefaultTransport (in order to guard against changes to the shared value).

I propose that we move the HTTP client and transport creation to the initialisation of the data source so we can take advantage of connection reuse. Consecutive calls to Read() can use the same instance of the client instead of building its own each time.

Incidentally, the go-retryablehttp client whose transport is replaced by the clone above itself relies on a library that creates its own instance of a http client and transport (go-cleanhttp), so if you were to use the client by itself you would have the same issue.

How much impact is this issue causing?

Medium

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nickabousselam nickabousselam changed the title Move HTTP client creation to provider Init Allow reuse of HTTP connection Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant