Skip to content

Fix assertion error on multiple node search reduce errors #131085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cbuescher
Copy link
Member

When receiving exceptions from more than one node on data node search reduction, SearchQueryThenFetchAsyncAction will raise more than one phase failure. This can lead to calling the listener in AbstractSearchAsyncAction more than once, which in turn in tests trips an assertion in ActionListener#assertFirstRun.

When receiving exceptions from more than one node on data node search
reduction, SearchQueryThenFetchAsyncAction will raise more than one
phase failure. This can lead to calling the listener in
AbstractSearchAsyncAction more than once, which in turn in tests trips
an assertion in ActionListener#assertFirstRun.
@cbuescher cbuescher added >test Issues or PRs that are addressing/adding tests :Search Foundations/Search Catch all for Search Foundations v9.2.0 labels Jul 11, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Jul 11, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@cbuescher
Copy link
Member Author

I ran into this issue while working on #129445 where another test in this suite fails for probably other reasons ("testSortMixedFieldTypes"). The test provokes IllegalArgumentExceptions when sorting on two indices with incompatible sort types.
When I couldn't reproduce the issue in #129445, I increased the index size to more than just one document and frequenty began running into another issue, namely getting errors of this kind:

https://gradle-enterprise.elastic.co/s/hjhqq6ium3hru/tests/task/:server:internalClusterTest/details/org.elasticsearch.search.sort.FieldSortIT/testSortMixedFieldTypesSeveralDocs?top-execution=1

WARNING: Uncaught exception in thread: Thread[#144,elasticsearch-error-rethrower,5,TGRP-FieldSortIT]
java.lang.AssertionError: java.lang.AssertionError: [org.elasticsearch.action.ActionListenerImplementations$RunBeforeActionListener/org.elasticsearch.action.search.TransportSearchAction$SearchResponseActionListener/org.elasticsearch.action.ActionListenerImplementations$RunBeforeActionListener/org.elasticsearch.tasks.TaskManager$1{org.elasticsearch.client.internal.support.AbstractClient$RefCountedFuture@4419e4fa}{CancellableTask{Task{id=30, type='transport', action='indices:data/read/search', description='null', parentTask=unset, startTime=1752232559616, headers={}, startTimeNanos=14563851254166}, reason='null', isCancelled=false}}/org.elasticsearch.action.support.TransportAction$$Lambda/0x000003000192f800@68f5045c/org.elasticsearch.action.search.AbstractSearchAsyncAction$$Lambda/0x0000030001b7c490@44774f6e]
	at __randomizedtesting.SeedInfo.seed([B5D33B2621614AE9]:0)
	at org.elasticsearch.action.ActionListener$3.assertFirstRun(ActionListener.java:404)
	at org.elasticsearch.action.ActionListener$3.onFailure(ActionListener.java:422)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:652)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:629)
	at org.elasticsearch.action.search.SearchQueryThenFetchAsyncAction.onPhaseFailure(SearchQueryThenFetchAsyncAction.java:81)
	at org.elasticsearch.action.search.SearchQueryThenFetchAsyncAction$1.handleException(SearchQueryThenFetchAsyncAction.java:525)
	at 
[...]
Caused by: java.lang.AssertionError: [org.elasticsearch.action.ActionListenerImplementations$RunBeforeActionListener/org.elasticsearch.action.search.TransportSearchAction$SearchResponseActionListener/org.elasticsearch.action.ActionListenerImplementations$RunBeforeActionListener/org.elasticsearch.tasks.TaskManager$1{org.elasticsearch.client.internal.support.AbstractClient$RefCountedFuture@4419e4fa}{CancellableTask{Task{id=30, type='transport', action='indices:data/read/search', description='null', parentTask=unset, startTime=1752232559616, headers={}, startTimeNanos=14563851254166}, reason='null', isCancelled=false}}/org.elasticsearch.action.support.TransportAction$$Lambda/0x000003000192f800@68f5045c/org.elasticsearch.action.search.AbstractSearchAsyncAction$$Lambda/0x0000030001b7c490@44774f6e]
	... 42 more
Caused by: org.elasticsearch.ElasticsearchException: executed already
	at org.elasticsearch.action.ActionListener$3.assertFirstRun(ActionListener.java:403)
	... 41 more

[2025-07-11T14:15:59,717][WARN ][o.e.t.TcpTransport       ][node_s3][transport_worker][T#1] exception caught on transport layer [Netty4TcpChannel{localAddress=/127.0.0.1:49428, remoteAddress=127.0.0.1/127.0.0.1:14833, profile=default}], closing connection
org.elasticsearch.ElasticsearchException: executed already
	at org.elasticsearch.action.ActionListener$3.assertFirstRun(ActionListener.java:403) ~[main/:?]
	at org.elasticsearch.action.ActionListener$3.onFailure(ActionListener.java:422) ~[main/:?]
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:652) ~[main/:?]
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:629) ~[main/:?]
	at org.elasticsearch.action.search.SearchQueryThenFetchAsyncAction.onPhaseFailure(SearchQueryThenFetchAsyncAction.java:81) ~[main/:?]
	at org.elasticsearch.action.search.SearchQueryThenFetchAsyncAction$1.handleException(SearchQueryThenFetchAsyncAction.java:525) ~[main/:?]
	at org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1705) ~[main/:?]
	at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1485) ~[main/:?]

Without the change in AbstractSearchAsyncAction#onPhaseFailure in this PR this is reproducible for me with:

./gradlew ":server:internalClusterTest" --tests "org.elasticsearch.search.sort.FieldSortIT.testSortMixedFieldTypesSeveralDocs" -Dtests.seed=B5D33B2621614AE9:3C91376D67454DCD --no-build-cache

I'm not sure preventing propagating any subsequent phase failure in AbstractSearchAsyncAction like suggested here is the right way to solve this, also I'm not really sure what big of an issue calling the ActionListener twice is in practice but the test assertion seems to be there for a reason. Also this might still be related to the weird errors we get in #129445 since that issue also seems to be related to search exception handling.

Copy link
Contributor

@benchaplin benchaplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it seems wrong to raise multiple phase failures for multiple data node failures.

I'm hesitant about this change, is it possible we're relying on multiple runs of raisePhaseFailure / listener.onFailure(exception) here, one per node search exception? Would love to hear more of your thoughts on that.

@@ -621,6 +622,10 @@ protected BytesReference buildSearchContextId(ShardSearchFailure[] failures) {
* @param cause the cause of the phase failure
*/
public void onPhaseFailure(String phase, String msg, Throwable cause) {
if (phaseFailureEncountered.compareAndSet(false, true) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is what we want, but this change would be lighter weight if this check was moved to the caller in SearchQueryThenFetchAsyncAction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch >test Issues or PRs that are addressing/adding tests v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants