# Potential race condition in ChildMemoryCircuitBreaker.limit()

**URL:** <https://discuss.elastic.co/t/potential-race-condition-in-childmemorycircuitbreaker-limit/238996>\
**Category:** Elasticsearch\
**Created:** [June 28, 2020, 9:51am UTC](https://discuss.elastic.co/t/potential-race-condition-in-childmemorycircuitbreaker-limit/238996 "2020-06-28T09:51:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hackerwin7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hackerwin7/32/43223_2.png) [@hackerwin7](https://discuss.elastic.co/u/hackerwin7)\
**Post date:** [June 28, 2020, 9:51am UTC](https://discuss.elastic.co/t/potential-race-condition-in-childmemorycircuitbreaker-limit/238996/1 "2020-06-28T09:51:15Z")

</div>

In the method of `ChildMemoryCircuitBreaker.addEstimateBytesAndMaybeBreak()`, the `limit()` method would atomically compare and set the `used` value.

when we test the high qps query to ES-node, the major cost is `ChildMemoryCircuitBreaker.limit()` which cause to `AggregationPhase.preProcess()`'s cost is extremely high

If data node receive high qps complicated search request body, and data-node will be busy to create aggregator, and it will lead to `SumAggregator.<init>`, lead to `BigArrays.newDoubleArray()` and lead to `BigArrays.adjustBreaker()`, finally call `breaker.addEstimateBytesAndMaybeBreak` and `ChildMemoryCircuitBreaker.limit()`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 26, 2020, 9:51am UTC](https://discuss.elastic.co/t/potential-race-condition-in-childmemorycircuitbreaker-limit/238996/2 "2020-07-26T09:51:18Z")

</div>

Closed on July 26, 2020, 9:51am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
