# Elastic Search RequestOptions race condition(Is this a bug)?

**URL:** <https://discuss.elastic.co/t/elastic-search-requestoptions-race-condition-is-this-a-bug/225063>\
**Category:** Elasticsearch\
**Created:** [March 25, 2020, 8:30pm UTC](https://discuss.elastic.co/t/elastic-search-requestoptions-race-condition-is-this-a-bug/225063 "2020-03-25T20:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Hiller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dean_hiller/32/65058_2.png) [@Dean\_Hiller](https://discuss.elastic.co/u/Dean_Hiller)\
**Post date:** [March 25, 2020, 8:30pm UTC](https://discuss.elastic.co/t/elastic-search-requestoptions-race-condition-is-this-a-bug/225063/1 "2020-03-25T20:30:30Z")

</div>

Notice the RequestOptions object has this line

```
public static final RequestOptions DEFAULT = new Builder(
        Collections.emptyList(), HeapBufferedResponseConsumerFactory.DEFAULT, null).build();

```

everything is private so I can't construct RequestOptions NOR can I construct the private Builder

if I create a two new Request(each on different threads) and both of them have...

```
private RequestOptions options = RequestOptions.DEFAULT;

```

and DEFAULT is static!!

If I call  
requst.getOptions().getHeaders().add() //refers to the same DEFAULT object so that one is modified twice :(. instead of once in each thread.

then are modifying the same RequestOptions.DEFAULT object which is a race condition and a list ends up with 2 not 1 per request.

I can't figure out how to pass in my own RequestOptions to each Request object.

thanks,  
Dean

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 25, 2020, 9:14pm UTC](https://discuss.elastic.co/t/elastic-search-requestoptions-race-condition-is-this-a-bug/225063/2 "2020-03-25T21:14:24Z")

</div>

Does the documentation helps? [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html#java-rest-low-usage-request-options](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html#java-rest-low-usage-request-options)

---

<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:** [April 22, 2020, 9:14pm UTC](https://discuss.elastic.co/t/elastic-search-requestoptions-race-condition-is-this-a-bug/225063/3 "2020-04-22T21:14:36Z")

</div>

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