mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
Remove timeout logic from ReadRaw functions and add ReadRawWithContext (#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
This commit is contained in:
committed by
GitHub
parent
d205193daf
commit
ef3e3eace2
@@ -69,20 +69,46 @@ func (c *Logical) ReadWithDataWithContext(ctx context.Context, path string, data
|
||||
return c.ParseRawResponseAndCloseBody(resp, err)
|
||||
}
|
||||
|
||||
// ReadRaw attempts to read the value stored at the given Vault path
|
||||
// (without '/v1/' prefix) and returns a raw *http.Response.
|
||||
//
|
||||
// Note: the raw-response functions do not respect the client-configured
|
||||
// request timeout; if a timeout is desired, please use ReadRawWithContext
|
||||
// instead and set the timeout through context.WithTimeout or context.WithDeadline.
|
||||
func (c *Logical) ReadRaw(path string) (*Response, error) {
|
||||
return c.ReadRawWithData(path, nil)
|
||||
return c.ReadRawWithDataWithContext(context.Background(), path, nil)
|
||||
}
|
||||
|
||||
// ReadRawWithContext attempts to read the value stored at the give Vault path
|
||||
// (without '/v1/' prefix) and returns a raw *http.Response.
|
||||
//
|
||||
// Note: the raw-response functions do not respect the client-configured
|
||||
// request timeout; if a timeout is desired, please set it through
|
||||
// context.WithTimeout or context.WithDeadline.
|
||||
func (c *Logical) ReadRawWithContext(ctx context.Context, path string) (*Response, error) {
|
||||
return c.ReadRawWithDataWithContext(ctx, path, nil)
|
||||
}
|
||||
|
||||
// ReadRawWithData attempts to read the value stored at the given Vault
|
||||
// path (without '/v1/' prefix) and returns a raw *http.Response. The 'data' map
|
||||
// is added as query parameters to the request.
|
||||
//
|
||||
// Note: the raw-response functions do not respect the client-configured
|
||||
// request timeout; if a timeout is desired, please use
|
||||
// ReadRawWithDataWithContext instead and set the timeout through
|
||||
// context.WithTimeout or context.WithDeadline.
|
||||
func (c *Logical) ReadRawWithData(path string, data map[string][]string) (*Response, error) {
|
||||
return c.ReadRawWithDataWithContext(context.Background(), path, data)
|
||||
}
|
||||
|
||||
// ReadRawWithDataWithContext attempts to read the value stored at the given
|
||||
// Vault path (without '/v1/' prefix) and returns a raw *http.Response. The 'data'
|
||||
// map is added as query parameters to the request.
|
||||
//
|
||||
// Note: the raw-response functions do not respect the client-configured
|
||||
// request timeout; if a timeout is desired, please set it through
|
||||
// context.WithTimeout or context.WithDeadline.
|
||||
func (c *Logical) ReadRawWithDataWithContext(ctx context.Context, path string, data map[string][]string) (*Response, error) {
|
||||
// See note in client.go, RawRequestWithContext for why we do not call
|
||||
// Cancel here. The difference between these two methods are that the
|
||||
// former takes a Request object directly, whereas this builds one
|
||||
// up for the caller.
|
||||
ctx, _ = c.c.withConfiguredTimeout(ctx)
|
||||
return c.readRawWithDataWithContext(ctx, path, data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user