mattbaird/elastigo

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

Opened this issue · 0 comments

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

}