Skip to content

Commit 63587f7

Browse files
committed
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 674c5b2 commit 63587f7

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ public void onFailure(Exception replicaException) {
201201
private void onNoLongerPrimary(Exception failure) {
202202
final Throwable cause = ExceptionsHelper.unwrapCause(failure);
203203
final boolean nodeIsClosing = cause instanceof NodeClosedException
204-
|| (cause instanceof TransportException && "TransportService is closed stopped can't send request".equals(cause.getMessage()));
204+
|| (cause instanceof TransportException &&
205+
("TransportService is closed stopped can't send request".equals(cause.getMessage())
206+
|| "transport stopped, action: internal:cluster/shard/failure".equals(cause.getMessage())));
205207
final String message;
206208
if (nodeIsClosing) {
207209
message = String.format(Locale.ROOT,

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

Lines changed: 4 additions & 1 deletion
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)