-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Logical.ReadRawWithDataWithContext cancels response body #18658
Comments
Hi @terinjokes, Thanks for reporting this! The
I believe it's the later. We had to deprecate |
Actually, it appears that @cipherboy has already addressed this issue in #17750 PR from November |
It looks like that PR takes the former approach of duplicating the behavior from client, which seems to be the reason it was deprecated in the first place? |
#18708) Removing the timeout logic from raw-response functions and adding documentation comments. The following functions are affected: - `ReadRaw` - `ReadRawWithContext` (newly added) - `ReadRawWithData` - `ReadRawWithDataWithContext` The previous logic of using `ctx, _ = c.c.withConfiguredTimeout(ctx)` could cause a potential [context leak](https://pkg.go.dev/context): > Failing to call the CancelFunc leaks the child and its children until the parent is canceled or the timer fires. The go vet tool checks that CancelFuncs are used on all control-flow paths. Cancelling the context would have caused more issues since the context would be cancelled before the request body is closed. Resolves: #18658
Hi @terinjokes, I've merged the PR to fix this issue (removing timeout logic altogether from Since func GetCertifcateForAuthority(ctx context.Context, client *vault.Client, caName string) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), client.ClientTimeout())
defer cancel()
// the rest of the code is unchanged
} |
Yes, I also did that with the workaround of disabling the |
@averche Do you have an estimate of when the
|
@terinjokes It appears that you are importing I've updated vault's go.mod to SDK v0.7.0 and API v1.8.3 (#18765, #18773) but if you are building against |
Yes, it looks like I started using the testrig in my E2E tests before some of those warnings went in? |
Adding the following in go.mod worked for me: require (
github.com/hashicorp/vault v1.2.1-0.20230117213031-11f6aad2b293
github.com/hashicorp/vault/api v1.8.3
) Hope this helps! In general, as I mentioned above, removing the dependency on |
I plan on just pulling on the binary and wiring it up to the test runner. Fortunately, I've already isolated the E2Es from the rest of the project. Thanks, we can probably call it done here. |
Describe the bug
To fetch the public certificates of certificate authorities from the PKI plugin, I was using the Client's
RawRequestWithContext
function, which has since been deprecated. I've migrated to the Logical client'sReadRawWithDataWithContext
function, but found it to be inconsistently failing.To support client HTTP timeouts, both implementations call
context.WithTimeout
. However,RawRequestWithContext
never called the cancel function.vault/api/client.go
Lines 1268 to 1277 in c782b66
The replacement
ReadRawWithDataWithContext
does call cancel, which occasionally starts causing failures reading the response body.vault/api/logical.go
Lines 101 to 106 in c782b66
(Note that this code block eventually calls the above deprecated function via
readRawWithDataWithContext
)To Reproduce
Since the failure seems to depend on the precise scheduling of the Go runtime, and behavior of select cases, I've been unable to develop an example that consistently fails. However, as an partial example:
With using a Vault client generated with
vault.DefaultConfig()
, this function will eventually unexpectedly fail with the following error:reading body from Vault: context canceled
. After disabling the HTTP timeout in the Vault client (eg,config.Timeout = 0
) I've been unable to reproduce this error.Expected behavior
I can't see the use case for closing the body of a
ReadRaw*
request before the caller has a chance to inspect is the intended result of these APIs.Should I open a PR to duplicate the note and behavior from Client? Or was this timeout behavior only intended on the non-raw paths?
The text was updated successfully, but these errors were encountered: