api: fix WriteRawWithContext/PatchRawWithContext premature context cancel - #32017
Open
arashzjahangiri wants to merge 1 commit into
Open
api: fix WriteRawWithContext/PatchRawWithContext premature context cancel#32017arashzjahangiri wants to merge 1 commit into
arashzjahangiri wants to merge 1 commit into
Conversation
…ncel
WriteRawWithContext and PatchRawWithContext both route through writeRaw,
which installed a withConfiguredTimeout cancel and deferred it:
func (c *Logical) writeRaw(ctx context.Context, request *Request) (*Response, error) {
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
defer cancelFunc() // fires before caller reads resp.Body
resp, err := c.c.rawRequestWithContext(ctx, request)
return resp, err
}
The defer fires the moment writeRaw returns, cancelling the context the
response body is bound to. For small responses the body is already fully
buffered so the race is invisible; for large responses (still streaming at
read time) the caller gets a spurious "context canceled" even though the
request succeeded server-side.
This is the same defect that was fixed for the read path in PR hashicorp#18708 and
is already absent from ReadRawWithDataWithContext and DeleteRawWithContext,
both of which call RawRequestWithContext directly without wrapping the
context in withConfiguredTimeout.
Fix: remove the withConfiguredTimeout/defer pattern from writeRaw and
delegate to RawRequestWithContext directly, matching the read/delete raw
path. Callers who need a timeout can set one on the context they pass in.
Also adds doc comments to WriteRaw, WriteRawWithContext, PatchRaw and
PatchRawWithContext noting that raw-response functions do not apply the
client-configured timeout, consistent with the existing comments on the
read/delete raw variants.
Fixes hashicorp#31986
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WriteRawWithContextandPatchRawWithContextboth route throughwriteRaw, which installed awithConfiguredTimeoutcancel and deferred it:The
deferfires the momentwriteRawreturns, cancelling the context the response body is bound to. For small responses the body is fully buffered before the cancel matters; for large responses still streaming at read time, the caller gets a spuriouscontext canceledeven though the request succeeded server-side.This is the exact defect fixed for the read path in #18708 and is already absent from
readRawWithDataWithContextandDeleteRawWithContext, both of which callRawRequestWithContextdirectly.Fix
Remove
withConfiguredTimeout/defer cancelFunc()fromwriteRawand delegate toRawRequestWithContextdirectly — identical to the pattern already used by the read/delete raw paths:Callers who need a timeout can set one on the context they pass in (via
context.WithTimeoutorcontext.WithDeadline).Also adds doc comments to
WriteRaw,WriteRawWithContext,PatchRaw, andPatchRawWithContextnoting that raw-response functions do not apply the client-configured timeout — consistent with existing comments on the read/delete raw variants.Testing
Added
TestWriteRawWithContextBodyReadablecovering bothWriteRawWithContextandPatchRawWithContext: starts a real test HTTP server, calls each method, and verifies the response body is fully readable after the call returns.Fixes #31986