Skip to content

Commit 7b0f3c0

Browse files
committed
Add conditional check
1 parent 64085d6 commit 7b0f3c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

server/src/main/java/org/elasticsearch/persistent/PersistentTasksService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,18 @@ default void onTimeout(TimeValue timeout) {
474474
}
475475

476476
private Client getDefaultOrProjectClient(@Nullable ProjectId projectId) {
477-
return projectId == null ? client : client.projectClient(projectId);
477+
if (projectId == null) {
478+
return client;
479+
}
480+
481+
final var currentProjectId = client.projectResolver().getProjectId();
482+
if (projectId.equals(currentProjectId)) {
483+
// The projectId will already be used in the client through thread context, so no need to set it again
484+
return client;
485+
} else {
486+
// Execute will throw if the projectId conflicts with the one in the current context
487+
return client.projectClient(projectId);
488+
}
478489
}
479490

480491
/**

0 commit comments

Comments
 (0)