Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/133111.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 133111
summary: Return 429 instead of 500 for timeout handlers
area: Network
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.elasticsearch.action.admin.cluster.node.tasks;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.ResourceNotFoundException;
Expand Down Expand Up @@ -41,6 +42,7 @@
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.tasks.RemovedTaskListener;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -677,9 +679,14 @@ private void waitForTimeoutTestCase(Function<TaskId, ? extends Iterable<? extend
Iterable<? extends Throwable> failures = wait.apply(taskId);

for (Throwable failure : failures) {
assertNotNull(
ExceptionsHelper.unwrap(failure, ElasticsearchTimeoutException.class, ReceiveTimeoutTransportException.class)
final Throwable cause = ExceptionsHelper.unwrap(
failure,
ElasticsearchTimeoutException.class,
ReceiveTimeoutTransportException.class
);
assertNotNull(cause);
assertThat(asInstanceOf(ElasticsearchException.class, cause).status(), equalTo(RestStatus.TOO_MANY_REQUESTS));
assertTrue(asInstanceOf(ElasticsearchException.class, cause).isTimeout());
}
} finally {
// Now we can unblock those requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;

Expand All @@ -29,4 +30,15 @@ public synchronized Throwable fillInStackTrace() {
// stack trace is uninformative
return this;
}

@Override
public RestStatus status() {
// closest thing to "your request took longer than you asked for"
return RestStatus.TOO_MANY_REQUESTS;
}

@Override
public boolean isTimeout() {
return true;
}
}