Skip to content
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

Empty api.Response.Body returned when Content-Length is non-zero #4973

Closed
ebilling opened this issue Jul 23, 2018 · 6 comments
Closed

Empty api.Response.Body returned when Content-Length is non-zero #4973

ebilling opened this issue Jul 23, 2018 · 6 comments
Milestone

Comments

@ebilling
Copy link

ebilling commented Jul 23, 2018

Describe the bug
In an integration test, I started noticing about a month ago that repeated requests would occasionally return an error. After much digging, I found that the api.Response.Body contained no data, while the Content-Length was correctly set.

After much more digging, I discovered the problem. In function:

func (c *Client) RawRequest(r *Request) (*Response, error) {

.........

var result *Response
resp, err := client.Do(req)
if cancelFunc != nil {
	cancelFunc()
}
if resp != nil {
	result = &Response{Response: resp}
}

should be:

if cancelFunc != nil {
	defer cancelFunc()
}
var result *Response
resp, err := client.Do(req)
if resp != nil {
	result = &Response{Response: resp}
}

see documentation for WithTimeout:

// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this Context complete:
//
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
// defer cancel() // releases resources if slowOperation completes before timeout elapses
// return slowOperation(ctx)
// }

To Reproduce
Steps to reproduce the behavior:
1.) Using the go API, set up a loop that reads the same secret repeatedly with a low timeout (I used 1 second) on the same system that's running the instance of vault you are testing against.
2.) Track whether the secret is returned.

Expected behavior
If the data has been returned to the client, it should be returned.

Environment:

  • Vault Server Version (retrieve with vault status): Version 0.10.3
  • Vault CLI Version (retrieve with vault version): Vault v0.10.3 (cgo)
  • Server Operating System/Architecture: MacOS and Linux
@jefferai
Copy link
Member

The problem with deferring is that we support retries so these could pile up. However, it's good to know that canceling a context will actually wipe the data. The documentation is frustratingly vague for what "releases sesources associated with it means" since that's going to depend strongly on individual package behavior.

@jefferai
Copy link
Member

Can you check out the cancelshift branch and see if that fixes things for you?

@ebilling
Copy link
Author

ebilling commented Jul 24, 2018 via email

@briankassouf
Copy link
Contributor

briankassouf commented Jul 24, 2018

@ebilling would you mind testing #4987

@briankassouf
Copy link
Contributor

@ebilling in case you are looking at email i meant #4987

@jefferai
Copy link
Member

(Also see #4987 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants