-
Notifications
You must be signed in to change notification settings - Fork 619
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
[ca]: Add a 5-second timeout to an external CA signing request #2064
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2064 +/- ##
==========================================
- Coverage 54.26% 54.15% -0.12%
==========================================
Files 111 111
Lines 19351 19326 -25
==========================================
- Hits 10501 10466 -35
- Misses 7582 7584 +2
- Partials 1268 1276 +8 Continue to review full report at Codecov.
|
ca/external.go
Outdated
@@ -154,7 +155,8 @@ func (eca *ExternalCA) CrossSignRootCA(ctx context.Context, rca RootCA) ([]byte, | |||
} | |||
|
|||
func makeExternalSignRequest(ctx context.Context, client *http.Client, url string, csrJSON []byte) (cert []byte, err error) { | |||
resp, err := ctxhttp.Post(ctx, client, url, "application/json", bytes.NewReader(csrJSON)) | |||
requestCtx, _ := context.WithTimeout(ctx, 5*time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call the cancel function after the context is no longer needed. That will ensure resources get freed, instead of possibly having them tied up for 5 seconds.
Thanks. Have you tested this? |
1da8ad8
to
d15a5b3
Compare
@aaronlehmann Previously I only tested manually, but I've added a test that an individual call to an external server is timed out. |
ca/external.go
Outdated
func makeExternalSignRequest(ctx context.Context, client *http.Client, url string, csrJSON []byte) (cert []byte, err error) { | ||
resp, err := ctxhttp.Post(ctx, client, url, "application/json", bytes.NewReader(csrJSON)) | ||
func makeExternalSignRequest(ctx context.Context, client *http.Client, url string, csrJSON []byte, timeout time.Duration) (cert []byte, err error) { | ||
requestCtx, cancel := context.WithTimeout(ctx, timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to move the context creation outside makeExternalSignRequest
. Passing in a timeout is a bit redundant with passing in a context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks
Thanks for the test! |
d15a5b3
to
5bc6637
Compare
LGTM |
ping @diogomonica please review |
Signed-off-by: cyli <ying.li@docker.com>
5bc6637
to
7498dcc
Compare
cc @aaronlehmann