meilisearch / meilisearch-java

Java client for Meilisearch

Home Page:https://meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WaitForTask timeout in case of a task cancellation

irevoire opened this issue · comments

commented

Description
Hello, I was looking for bugs in the SDK and realized that when we call WaitForTask:

while (status == null
|| (!status.equals(TaskStatus.SUCCEEDED) && !status.equals(TaskStatus.FAILED))) {
if (elapsedTime >= timeoutInMs) {
throw new MeilisearchTimeoutException();
}
task = this.getTask(taskUid);
status = task.getStatus();

This condition is wrong:

status == null
                || (!status.equals(TaskStatus.SUCCEEDED) && !status.equals(TaskStatus.FAILED))

If the task gets canceled, then the loop hangs forever until it times out.
Instead of checking if the task has succeeded or failed, we should instead use this condition:

status == null
                || (status.equals(TaskStatus.ENQUEUED) || status.equals(TaskStatus.PROCESSING))