-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix validate query listener invocation bug (#56157)
When the index we are validating a query does not exist, we try to send back a response letting the client know that the index does not exist. Yet, we accidentally fallthrough into the case that the validation failed for some other reason. This means that we end up notifying the channel twice. Sometimes the notification occurs after the failure has been written out and the channel closed (so the second invocation leads to a silent failed to write to a closed channel issue), and sometimes the response does end up in the channel, creating garbled responses to the client. This commit fixes that issue by avoiding the fallthrough.
- Loading branch information
1 parent
df09089
commit 085fa4a
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../elasticsearch/action/admin/indices/validate/query/TransportValidateQueryActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.validate.query; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class TransportValidateQueryActionTests extends ESSingleNodeTestCase { | ||
|
||
/* | ||
* This test covers a fallthrough bug that we had, where if the index we were validating against did not exist, we would invoke the | ||
* failure listener, and then fallthrough and invoke the success listener too. This would cause problems when the listener was | ||
* ultimately wrapping sending a response on the channel, as it could lead to us sending both a failure or success responses, and having | ||
* them garbled together, or trying to write one after the channel had closed, etc. | ||
*/ | ||
public void testListenerOnlyInvokedOnceWhenIndexDoesNotExist() { | ||
final AtomicBoolean invoked = new AtomicBoolean(); | ||
final ActionListener<ValidateQueryResponse> listener = new ActionListener<>() { | ||
|
||
@Override | ||
public void onResponse(final ValidateQueryResponse validateQueryResponse) { | ||
fail("onResponse should not be invoked in this failure case"); | ||
} | ||
|
||
@Override | ||
public void onFailure(final Exception e) { | ||
if (invoked.compareAndSet(false, true) == false) { | ||
fail("onFailure invoked more than once"); | ||
} | ||
} | ||
|
||
}; | ||
client().admin().indices().validateQuery(new ValidateQueryRequest("non-existent-index"), listener); | ||
assertThat(invoked.get(), equalTo(true)); // ensure that onFailure was invoked | ||
} | ||
|
||
} |