Skip to content

OnError callback in esutil.BulkIndexerConfig is invoked duplicately #497

@iamorchid

Description

@iamorchid

In bulk_indexer.go, I see logic below:

func (w *worker) run() {
	go func() {     
                                ...  
                                if err := w.flush(ctx); err != nil {
					w.mu.Unlock()
					if w.bi.config.OnError != nil {
						w.bi.config.OnError(ctx, err)
					}
					continue
				}
                                 ...
        }()
}
func (w *worker) flush(ctx context.Context) error {
...
	if res.IsError() {
		atomic.AddUint64(&w.bi.stats.numFailed, uint64(len(w.items)))
		// TODO(karmi): Wrap error (include response struct)
		if w.bi.config.OnError != nil {
			w.bi.config.OnError(ctx, fmt.Errorf("flush: %s", err))
		}
		return fmt.Errorf("flush: %s", res.String())
	}
...
}

When flush fails, bi.config.OnError is called twice. One happens in flush function, and the other in the run function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: HelpersImprovements or additions to the helpCategory: BugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions