Skip to content

Commit 2870c3c

Browse files
committed
Avoid race condition for subscribers
If several monitors (each is a subscriber) are attached to an everest server, the server could crash with a RuntimeError when tearing down; Traceback (most recent call last): File "/data/projects/ert/src/ert/dark_storage/endpoints/experiment_server.py", line 341, in run for sub in shared_data.subscribers.values(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: dictionary changed size during iteration This is because there is an await in the loop execution body, which allows the async loop to add a new subscriber while we are iterating. By expanding the values() iterator to a fixed list before looping, we avoid the possibility of a race condition (but we are leaving behind the possible late added subscriber) Repeated testing with multiple monitors with this patch has not revealed any further issues.
1 parent 6434fe3 commit 2870c3c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ert/dark_storage/endpoints/experiment_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async def run(self) -> None:
338338

339339
if isinstance(item, EndEvent):
340340
# Wait for subscribers to receive final events
341-
for sub in shared_data.subscribers.values():
341+
for sub in list(shared_data.subscribers.values()):
342342
await sub.is_done()
343343
break
344344
await simulation_future

0 commit comments

Comments
 (0)