Skip to content

Commit 660c7ed

Browse files
authored
Treat TransportService stopped error as node is closing (#39800)
If TransportService is stopped before a shard-failure request is sent but after the request is registered, TransportService will notify ReplicationOperation a TransportException with an error message: "transport stop, action: internal:cluster/shard/failure". Relates #39584
1 parent 833474e commit 660c7ed

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

server/src/main/java/org/elasticsearch/action/support/replication/ReplicationOperation.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ public String toString() {
206206
private void onNoLongerPrimary(Exception failure) {
207207
final Throwable cause = ExceptionsHelper.unwrapCause(failure);
208208
final boolean nodeIsClosing = cause instanceof NodeClosedException
209-
|| (cause instanceof TransportException && "TransportService is closed stopped can't send request".equals(cause.getMessage()));
209+
|| (cause instanceof TransportException &&
210+
("TransportService is closed stopped can't send request".equals(cause.getMessage())
211+
|| "transport stopped, action: internal:cluster/shard/failure".equals(cause.getMessage())));
210212
final String message;
211213
if (nodeIsClosing) {
212214
message = String.format(Locale.ROOT,

server/src/test/java/org/elasticsearch/action/support/replication/ReplicationOperationTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ public void testNoLongerPrimary() throws Exception {
205205
shardActionFailure = new NodeClosedException(new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT));
206206
} else if (randomBoolean()) {
207207
shardActionFailure = new SendRequestTransportException(
208-
new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT), "internal:cluster/shard/failure",
208+
new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT), ShardStateAction.SHARD_FAILED_ACTION_NAME,
209209
new TransportException("TransportService is closed stopped can't send request"));
210+
} else if (randomBoolean()) {
211+
shardActionFailure = new TransportException(
212+
"transport stopped, action: " + ShardStateAction.SHARD_FAILED_ACTION_NAME);
210213
} else {
211214
shardActionFailure = new ShardStateAction.NoLongerPrimaryShardException(failedReplica.shardId(), "the king is dead");
212215
}

0 commit comments

Comments
 (0)