Data race condition in automaton queries #105911
Labels
>bug
:Search/Search
Search-related issues that do not fall into other categories
Team:Search
Meta label for search team
Elasticsearch Version
8.12.1
Installed Plugins
No response
Java Version
bundled
OS Version
archlinux 6.7.8
Problem Description
First described in the post https://discuss.elastic.co/t/data-race-condition-in-automaton-queries/353937?u=yfful there seems to be a data race condition when evaluating automaton queries like
regexp
. In a local unit test involving a runtime field and a regexp query, I have experienced search inconsistencies with the result count.Steps to Reproduce
The query shown below uses the script
parity
which returnseven
orodd
depending on the value of another numeric field. It returns sometimes an unexpected number of hits.I believe that following this change that enabled parallelization by default, the queries extending
AbstractStringScriptFieldAutomatonQuery
have a data race condition. If I understand that change correctly, then the code below can be called concurrently:elasticsearch/server/src/main/java/org/elasticsearch/search/runtime/AbstractScriptFieldQuery.java
Lines 71 to 77 in f0e4317
Therefore, the
BytesRefBuilder
scratch below is shared by all threads that execute a search on different segments, which would lead to the race condition I am seeing. With the query shared above, thescratch
variable would containeven
for example, although thevalues
list passed in argument contains onlyodd
. The race condition would explain this inconsistency.elasticsearch/server/src/main/java/org/elasticsearch/search/runtime/AbstractStringScriptFieldAutomatonQuery.java
Line 20 in f0e4317
Logs (if relevant)
No response
The text was updated successfully, but these errors were encountered: