Skip to content

Commit

Permalink
Merge pull request #717 from SebastienLaurent/bugfix/elastic_store_panic
Browse files Browse the repository at this point in the history
Fix ES Store behaviour when ES in unreachable
  • Loading branch information
laurentganne committed Mar 22, 2021
2 parents 8c37330 + dfba07d commit f67f244
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions storage/internal/elastic/es_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func doQueryEs(c *elasticsearch6.Client, conf elasticStoreConf,
c.Search.WithSort("iid:"+order),
)
if e != nil {
err = errors.Wrapf(err, "Failed to perform ES search on index %s, query was: <%s>, error was: %+v", index, query, err)
err = errors.Wrapf(e, "Failed to perform ES search on index %s, query was: <%s>, error was: %+v", index, query, e)
return
}
defer closeResponseBody("Search:"+index, res)
Expand Down Expand Up @@ -299,9 +299,11 @@ func handleESResponseError(res *esapi.Response, requestDescription string, query

// Close response body, if an error occur, just print it
func closeResponseBody(requestDescription string, res *esapi.Response) {
err := res.Body.Close()
if err != nil {
log.Printf("[%s] Was not able to close resource response body, error was: %+v", requestDescription, err)
if res != nil && res.Body != nil {
err := res.Body.Close()
if err != nil {
log.Printf("[%s] Was not able to close resource response body, error was: %+v", requestDescription, err)
}
}
}

Expand Down

0 comments on commit f67f244

Please sign in to comment.