Skip to content

Commit

Permalink
Check elasticsearch response nil in bulk processor (jaegertracing#1467)
Browse files Browse the repository at this point in the history
* Avoid process crash when elasticsearch response is nil

Add nil pointer check in elasticsearch bulkprocessor's
after callback, defined inside pkg/es/config/config.go.
In some rare cases, elasticsearch request will return
error with nil response, and then nil response will
be passed into after callback, and using of nil pointer
will cause process crash.

Signed-off-by: Li Zhaoxing <lizhaoxing@4paradigm.com>

* Remove unnecessary wrap arround nil pointer in log
Signed-off-by: Li Zhaoxing <lizhaoxing@4paradigm.com>
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
  • Loading branch information
YEXINGZHE54 authored and stefanvassilev committed Apr 10, 2019
1 parent 151a729 commit 0ea4d95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
m.Delete(id)

// log individual errors, note that err might be false and these errors still present
if response.Errors {
if response != nil && response.Errors {
for _, it := range response.Items {
for key, val := range it {
if val.Error != nil {
Expand All @@ -127,7 +127,12 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac

sm.Emit(err, time.Since(start.(time.Time)))
if err != nil {
failed := len(response.Failed())
var failed int
if response == nil {
failed = 0
} else {
failed = len(response.Failed())
}
total := len(requests)
logger.Error("Elasticsearch could not process bulk request",
zap.Int("request_count", total),
Expand Down

0 comments on commit 0ea4d95

Please sign in to comment.