You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Flaky ElasticsearchIndexTest: a reading of the search statistics can miss a released scroll #5062
ElasticsearchIndexTest.shouldReleaseTheContextWhenTheConsumerStopsBeforeTheEnd fails now and then. Its check that the result was read through a scroll doesn't find the scroll counted:
ElasticsearchIndexTest.shouldReleaseTheContextWhenTheConsumerStopsBeforeTheEnd:1190->assertReadInPages:1301 this result is read through a scroll ==> expected: <true> but was: <false>
Cause: the test can read the statistics in the middle of a release
The tests of the search contexts read _nodes/stats/indices/search until open_contexts is back at the number they expect, then check scroll_total in that same reading.
Closing the stream releases the scroll context with a request the client doesn't wait for, right before the test's first reading. On OpenSearch and Elasticsearch 6, every paging mode reads this result through a scroll.
When a node frees a scroll context, it updates scroll_total and open_contexts one after the other, and it reads them one after the other when it reports them:
Elasticsearch 7.17, 8.15 and 9 and OpenSearch 2.19 and 3.9 count the freed scroll first, but read scroll_total first.
Elasticsearch 6.6 stops counting the context open first.
So a reading that overlaps the release can show the context gone without its scroll. The next reading, a round trip later, has both.
Reproduction: repeat the test's scenario (read the first hit, close the stream, wait for the open contexts) and keep the first reading in which the open contexts are back. It missed the released scroll:
in 4 of 300 rounds on OpenSearch 2.19.6;
in 2 of 300 on Elasticsearch 9.5.4;
in 9 of 300 on Elasticsearch 6.6.0.
The reading after it missed it in none of them.
Proposed fix: the tests take two readings in a row in which the open contexts are back at the expected number, and use the second.
Activity
Take two readings of the search statistics once contexts are released