Skip to content

Commit 1fdbb6c

Browse files
authored
fix: race condition in parallel kind processing (#744)
This race condition happens because `all_tasks` is updated in a callback, which runs asynchronously, but `kinds` and `edges` are updated in the main loop. This leads to a potential mismatch when the logic at the start of `submit_ready_kinds` runs: if `all_tasks` is updated but the other two are not, the data we feed into `load_tasks` will be incorrect.
1 parent 434fba6 commit 1fdbb6c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/taskgraph/generator.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ def _load_tasks(self, kinds, kind_graph, parameters):
267267
futures = set()
268268
edges = set(kind_graph.edges)
269269

270-
def add_new_tasks(future):
271-
for task in future.result():
272-
if task.label in all_tasks:
273-
raise Exception("duplicate tasks with label " + task.label)
274-
all_tasks[task.label] = task
275-
276270
with ProcessPoolExecutor() as executor:
277271

278272
def submit_ready_kinds():
@@ -303,7 +297,6 @@ def submit_ready_kinds():
303297
},
304298
self._write_artifacts,
305299
)
306-
future.add_done_callback(add_new_tasks)
307300
futures.add(future)
308301
futures_to_kind[future] = name
309302

@@ -317,6 +310,11 @@ def submit_ready_kinds():
317310
kind = futures_to_kind.pop(future)
318311
futures.remove(future)
319312

313+
for task in future.result():
314+
if task.label in all_tasks:
315+
raise Exception("duplicate tasks with label " + task.label)
316+
all_tasks[task.label] = task
317+
320318
# Update state for next batch of futures.
321319
del kinds[kind]
322320
edges = {e for e in edges if e[1] != kind}

0 commit comments

Comments
 (0)