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

Fix artifact up/download timeouts #3033

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/agenthttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"golang.org/x/net/http2"
)

// NewClient creates a HTTP client.
// NewClient creates a HTTP client. Note that the default timeout is 60 seconds;
// for some use cases (e.g. artifact operations) use [WithNoTimeout].
func NewClient(opts ...ClientOption) *http.Client {
conf := clientConfig{
// This spells out the defaults, even if some of them are zero values.
Expand Down Expand Up @@ -62,6 +63,7 @@ func WithAuthBearer(b string) ClientOption { return func(c *clientConfig) {
func WithAuthToken(t string) ClientOption { return func(c *clientConfig) { c.Token = t } }
func WithAllowHTTP2(a bool) ClientOption { return func(c *clientConfig) { c.AllowHTTP2 = a } }
func WithTimeout(d time.Duration) ClientOption { return func(c *clientConfig) { c.Timeout = d } }
func WithNoTimeout(c *clientConfig) { c.Timeout = 0 }
func WithTLSConfig(t *tls.Config) ClientOption { return func(c *clientConfig) { c.TLSConfig = t } }

type ClientOption = func(*clientConfig)
Expand Down
5 changes: 4 additions & 1 deletion internal/artifact/artifactory_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func (d ArtifactoryDownloader) Start(ctx context.Context) error {
"Authorization": fmt.Sprintf("Basic %s", getBasicAuthHeader(username, password)),
}

client := agenthttp.NewClient(agenthttp.WithAllowHTTP2(!d.conf.DisableHTTP2))
client := agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!d.conf.DisableHTTP2),
agenthttp.WithNoTimeout,
)

// We can now cheat and pass the URL onto our regular downloader
return NewDownload(d.logger, client, DownloadConfig{
Expand Down
1 change: 1 addition & 0 deletions internal/artifact/artifactory_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewArtifactoryUploader(l logger.Logger, c ArtifactoryUploaderConfig) (*Arti
conf: c,
client: agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!c.DisableHTTP2),
agenthttp.WithNoTimeout,
),
iURL: parsedURL,
Path: path,
Expand Down
2 changes: 2 additions & 0 deletions internal/artifact/bk_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (u *bkMultipartUpload) DoWork(ctx context.Context) (*api.ArtifactPartETag,

client := agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!u.conf.DisableHTTP2),
agenthttp.WithNoTimeout,
)

resp, err := agenthttp.Do(u.logger, client, req,
Expand Down Expand Up @@ -208,6 +209,7 @@ func (u *bkFormUpload) DoWork(ctx context.Context) (*api.ArtifactPartETag, error
// Create the client
client := agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!u.conf.DisableHTTP2),
agenthttp.WithNoTimeout,
)

// Perform the request
Expand Down
5 changes: 4 additions & 1 deletion internal/artifact/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ func (a *Downloader) createDownloader(artifact *api.Artifact, path, destination
})

default:
client := agenthttp.NewClient(agenthttp.WithAllowHTTP2(!a.conf.DisableHTTP2))
client := agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!a.conf.DisableHTTP2),
agenthttp.WithNoTimeout,
)
return NewDownload(a.logger, client, DownloadConfig{
URL: artifact.URL,
Path: path,
Expand Down
5 changes: 4 additions & 1 deletion internal/artifact/s3_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (d S3Downloader) Start(ctx context.Context) error {
}

// We can now cheat and pass the URL onto our regular downloader
client := agenthttp.NewClient(agenthttp.WithAllowHTTP2(!d.conf.DisableHTTP2))
client := agenthttp.NewClient(
agenthttp.WithAllowHTTP2(!d.conf.DisableHTTP2),
agenthttp.WithNoTimeout,
)
return NewDownload(d.logger, client, DownloadConfig{
URL: signedURL,
Path: d.conf.Path,
Expand Down