Skip to content

Add option to specify a client timeout #2191

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

Merged
merged 2 commits into from
Apr 1, 2025
Merged

Add option to specify a client timeout #2191

merged 2 commits into from
Apr 1, 2025

Conversation

maraino
Copy link
Contributor

@maraino maraino commented Feb 25, 2025

Description

This commit adds a new option to specify the client timeout to the CA client.

Fixes #2176

@maraino maraino requested a review from hslatman February 25, 2025 19:31
@github-actions github-actions bot added the needs triage Waiting for discussion / prioritization by team label Feb 25, 2025
@maraino maraino force-pushed the mariano/timeout branch 2 times, most recently from f5425ff to 1a05f48 Compare February 25, 2025 20:33
@hslatman hslatman added this to the v0.28.3 milestone Feb 27, 2025
Comment on lines 584 to 592
return &Client{
client: newClient(tr),
client: newClient(tr, o.timeout),
endpoint: u,
retryFunc: o.retryFunc,
timeout: o.timeout,
opts: opts,
}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you also set a default timeout? I believe without a default timeout set, it will just wait until the server disconnects based on its timeouts (if any). See the output for different cases below. I know this client will be used with our CA, and we're in control over those timeouts, but it's generally a good practice to set a timeout in any http.Client that is created.

The WithContext methods can also be used, and they seem to behave as expected. However, we're not setting timeouts through the context in places where we use those methods.

# timeout on connection triggered by server; no (default) timeout in the HTTP client or context:
$ go run cmd/step/main.go ca health 
client GET https://127.0.0.1:8443/health failed: stream error: stream ID 1; INTERNAL_ERROR; received from peer

# timeout on the context from the client side:
$ go run cmd/step/main.go ca health
client GET https://127.0.0.1:8443/health failed: context deadline exceeded
exit status 1

# timeout on the client:
$ go run cmd/step/main.go ca health
client GET https://127.0.0.1:8443/health failed: context deadline exceeded (Client.Timeout exceeded while awaiting headers)
exit status 1

Copy link
Member

Choose a reason for hiding this comment

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

@maraino I've added the default timeout in 3135a2c.

@hslatman hslatman self-assigned this Mar 3, 2025
@hslatman hslatman modified the milestones: v0.28.3, v0.28.4 Mar 18, 2025
This commit adds to the ca Client a new option to specify the client
timeout.

Fixes #2176
@hslatman hslatman requested a review from a team April 1, 2025 14:29
@hslatman hslatman removed their assignment Apr 1, 2025
@hslatman hslatman self-requested a review April 1, 2025 14:31
@hslatman hslatman merged commit 60c0b0a into master Apr 1, 2025
13 checks passed
@hslatman hslatman deleted the mariano/timeout branch April 1, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Waiting for discussion / prioritization by team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ca.NewClient don't allow setting a timeout for the http client
3 participants