Skip to content

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

Description

@q96456

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

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions