Skip to content

Commit 2d0d2b2

Browse files
authored
Merge pull request #919 from fractal-analytics-platform/918_apply_registration_race_condition
Fix race condition handling in apply registration task
2 parents 99074da + 127341b commit 2d0d2b2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
**Note**: Numbers like (\#123) point to closed Pull Requests on the fractal-tasks-core repository.
22

3-
# Unreleased
3+
# 1.4.3
44

5+
* Tasks:
6+
* Update apply_registration_to_image to handle race conditions better (\#919).
57
* Testing
68
* Add `spherical-harmonics` extra to scmultiplex, for testing manifest build (\#899).
79
* Move manifest-creation CI to Python 3.11 (\#915).

fractal_tasks_core/tasks/apply_registration_to_image.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,34 @@ def apply_registration_to_image(
205205
# Get the relevant metadata of the Zarr table & add it
206206
# See issue #516 for the need for this workaround
207207
max_retries = 20
208-
sleep_time = 5
208+
sleep_time = 10
209209
current_round = 0
210210
while current_round < max_retries:
211211
try:
212212
old_table_group = zarr.open_group(
213213
table_dict[table], mode="r"
214214
)
215215
current_round = max_retries
216-
except zarr.errors.GroupNotFoundError:
216+
curr_table = ad.read_zarr(table_dict[table])
217+
break # Exit loop on success
218+
except (
219+
zarr.errors.GroupNotFoundError,
220+
zarr.errors.PathNotFoundError,
221+
):
217222
logger.debug(
218223
f"Table {table} not found in attempt {current_round}. "
219224
f"Waiting {sleep_time} seconds before trying again."
220225
)
221226
current_round += 1
222227
time.sleep(sleep_time)
228+
else:
229+
# This runs only if the loop exits via exhaustion
230+
raise RuntimeError(
231+
f"Table {table} not found after {max_retries} attempts."
232+
"Check whether this table actually exists. If it does, "
233+
"this may be a race condition issue."
234+
)
223235
# Write the Zarr table
224-
curr_table = ad.read_zarr(table_dict[table])
225236
write_table(
226237
new_image_group,
227238
table,

0 commit comments

Comments
 (0)