Skip to content

fix(java): ensure waitTask exception propagation#799

Open
eric-zaharia wants to merge 2 commits into
v3from
fix/waitTask-exception-handling
Open

fix(java): ensure waitTask exception propagation#799
eric-zaharia wants to merge 2 commits into
v3from
fix/waitTask-exception-handling

Conversation

@eric-zaharia

@eric-zaharia eric-zaharia commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Related Issue API-473
Need Doc update no

Jira ticket: API-473

Describe your change

TaskUtils.waitTask polls task status in a while (true) loop and, on InterruptedException / ExecutionException from getTask, silently breaked out of the loop. Because waitTask returns void, a swallowed exception was indistinguishable from a genuine "published" confirmation.

This PR replaces the silent break with proper exception propagation, mirroring the LaunderThrowable pattern already used throughout the client:

  • InterruptedException → restore the thread's interrupt flag, then rethrow as AlgoliaRuntimeException.
  • ExecutionException → unwrap the real cause via LaunderThrowable.launder, surfacing the underlying AlgoliaApiException / AlgoliaRetryException / AlgoliaRuntimeException.

After the change the loop has only two exits: a real "published" status (return) or a thrown exception. It can no longer return as if a task completed when it did not.

What problem is this fixing?

If waitTask silently exited after the copy step (a transient network error, or getTask being retried on a host that had not yet registered the task), replaceAllObjects proceeded as though the copy had completed:

  1. settings / rules / synonyms were not confirmed copied into the tmp index;
  2. records were batched into the tmp index;
  3. the tmp index was atomically moved over the main index.

Result: the main index keeps its records but loses its settings, rules, and synonyms (reset to defaults) — a silent partial wipeout, with no error surfaced to the caller. This is exactly the incident reported in CR-11430.

This bug is unique to the Java v3 (legacy) client — v4 and every other legacy client propagate the exception. v4 is already safe via TaskUtils.retryUntil (no try/catch around the supplier) plus a replaceAllObjects cleanup wrapper.

@eric-zaharia eric-zaharia self-assigned this Jun 4, 2026
@codacy-production

codacy-production Bot commented Jun 4, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes.

@eric-zaharia eric-zaharia marked this pull request as ready for review June 8, 2026 07:42
@eric-zaharia eric-zaharia requested a review from aallam as a code owner June 8, 2026 07:42
@eric-zaharia eric-zaharia requested a review from Fluf22 June 8, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant