Skip to content

Commit dc92c83

Browse files
authored
Change Elasticsearch timeouts to 429 response instead of 5xx (#116026)
When a user passes a timeout to an Elasticsearch request, the user is telling the system to limit how long the request should take. If that timeout is breached, it is because the user selected a timeout less than the time the request needed. Therefore, it is up to the user to select a long enough time. If they don't, it's on the user to adjust their request. Given the above, a breached timeout is an issue with the user request, and the http response code should refelect that. This commit changes timeout exceptions to give a 429 response code instead of the current 5xx.
1 parent 375814d commit dc92c83

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

docs/changelog/116026.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pr: 116026
2+
summary: Change Elasticsearch timeouts to 429 response instead of 5xx
3+
area: Infra/Core
4+
type: breaking
5+
issues: []
6+
breaking:
7+
title: Change most Elasticsearch timeouts to 429 response instead of 5xx
8+
area: REST API
9+
details: When a timeout occurs in most REST requests, whether via a per-request timeout, or a system default, the
10+
request would return a 5xx response code. The response code from those APIs when a timeout occurs is now 429.
11+
impact: Adjust any code relying on retrying on 5xx responses for timeouts to look for a 429 response code and
12+
inspect the response to determine whether a timeout occured.
13+
notable: false

server/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch;
1111

1212
import org.elasticsearch.common.io.stream.StreamInput;
13+
import org.elasticsearch.rest.RestStatus;
1314

1415
import java.io.IOException;
1516

@@ -34,4 +35,10 @@ public ElasticsearchTimeoutException(String message, Object... args) {
3435
public ElasticsearchTimeoutException(String message, Throwable cause, Object... args) {
3536
super(message, cause, args);
3637
}
38+
39+
@Override
40+
public RestStatus status() {
41+
// closest thing to "your request took longer than you asked for"
42+
return RestStatus.TOO_MANY_REQUESTS;
43+
}
3744
}

server/src/main/java/org/elasticsearch/cluster/metadata/ProcessClusterEventTimeoutException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public ProcessClusterEventTimeoutException(StreamInput in) throws IOException {
2828

2929
@Override
3030
public RestStatus status() {
31-
return RestStatus.SERVICE_UNAVAILABLE;
31+
return RestStatus.TOO_MANY_REQUESTS;
3232
}
3333
}

server/src/main/java/org/elasticsearch/search/query/SearchTimeoutException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public SearchTimeoutException(StreamInput in) throws IOException {
3131

3232
@Override
3333
public RestStatus status() {
34-
return RestStatus.GATEWAY_TIMEOUT;
34+
return RestStatus.TOO_MANY_REQUESTS;
3535
}
3636

3737
/**

0 commit comments

Comments
 (0)