Skip to content

Commit 8388423

Browse files
cristovargheseChristo Varghese
andauthored
Fix for data race condition (digitalocean#26)
Co-authored-by: Christo Varghese <christov@juniper.net>
1 parent a91ba6d commit 8388423

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

node/elasticsearch/connectionfactory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ func newEsBulkServiceFactory(ctx context.Context, url string, esUsername string,
5555
func (e *esBulkServiceFactory) BulkService() bulkService {
5656

5757
// periodically establish a new connection to help prevent hotspots in ES clusters with multiple client nodes
58-
atomic.AddInt64(&e.batchCount, 1)
59-
if e.batchCount == e.reconnectBatches {
58+
count := atomic.AddInt64(&e.batchCount, 1)
59+
if count == e.reconnectBatches {
6060
e.reconnect(e.ctx)
61-
e.batchCount = 0
61+
atomic.StoreInt64(&e.batchCount, 0)
6262
}
6363

6464
// read lock before using the client conn allows many goroutines to run at once while blocking operations during a reconnect

0 commit comments

Comments
 (0)