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

No timeout set for search function in file "coresearch.go" #300

Open
q96456 opened this issue Aug 15, 2019 · 0 comments
Open

No timeout set for search function in file "coresearch.go" #300

q96456 opened this issue Aug 15, 2019 · 0 comments

Comments

@q96456
Copy link

q96456 commented Aug 15, 2019

Because no function to set timeout, if I write error address of ESCluster, process will block at " r.hostResponse.Mark(err)".
func (r *Request) DoResponse(v interface{}) (*http.Response, []byte, error) {
var client = r.Client
if client == nil {
client = http.DefaultClient
}

res, err := client.Do(r.Request)
// Inform the HostPool of what happened to the request and allow it to update
 r.hostResponse.Mark(err)
if err != nil {
	return nil, nil, err
}

defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)

if err != nil {
	return nil, nil, err
}

if res.StatusCode == 404 {
	return nil, bodyBytes, RecordNotFound
}

if res.StatusCode > 304 && v != nil {
	// Make sure the response is JSON and not some other type.
	// i.e. 502 or 504 errors from a proxy.
	mediaType, _, err := mime.ParseMediaType(res.Header.Get("Content-Type"))
	if err != nil {
		return nil, bodyBytes, err
	}

	if mediaType != "application/json" {
		return nil, bodyBytes, fmt.Errorf(http.StatusText(res.StatusCode))
	}

	jsonErr := json.Unmarshal(bodyBytes, v)
	if jsonErr != nil {
		return nil, nil, fmt.Errorf("Json response unmarshal error: [%s], response content: [%s]", jsonErr.Error(), string(bodyBytes))
	}
}
return res, bodyBytes, err

}

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

1 participant