mattbaird / elastigo

A Go (golang) based Elasticsearch client library.
Apache License 2.0
943 stars 241 forks source link

MAX_SHUTDOWN_SECS make me get into trouble #288

Closed wolfogre closed 1 year ago

wolfogre commented 7 years ago

When I use BulkIndexer to index data into ElasticSearch, I find that sometimes it would lost some data, the reason is that before the program exit, I will call BulkIndexer.Stop() to make sure all work have completed, the documents said "Stop stops the bulk indexer, blocking the caller until it is complete.", however, there is the code :

// Stop stops the bulk indexer, blocking the caller until it is complete.
func (b *BulkIndexer) Stop() {
    ch := make(chan struct{})
    b.shutdownChan <- ch
    select {
    case <-ch:
        // done
    case <-time.After(time.Second * time.Duration(MAX_SHUTDOWN_SECS)):
        // timeout!
    }
}

It shows that if the caller have be blocking for more than MAX_SHUTDOWN_SECS seconds, the Stop() will be timeout and return nothing.

BUT MAX_SHUTDOWN_SECS IS 5 SECONDS, some time it is not enough for me.

Is there any way to set up this value or know the timeout happend?

Thank you~