Skip to content

Commit

Permalink
zmq: make sure to destroy evaluator context in case zmq fails on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Jan 29, 2025
1 parent cb0726d commit 7e600dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ async def _server(self) -> None:
except zmq.error.ZMQError as e:
logger.error(f"ZMQ error encountered {e} during evaluator initialization")
self._server_started.set_exception(e)
raise
zmq_context.destroy(linger=0)
return
try:
await self._server_done.wait()
try:
Expand All @@ -338,7 +339,7 @@ async def _server(self) -> None:
finally:
try:
self._router_socket.close()
zmq_context.destroy()
zmq_context.destroy(linger=0)
except Exception as exc:
logger.warning(f"Failed to clean up zmq context {exc}")
logger.info("ZMQ cleanup done!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ async def test_evaluator_handles_dispatchers_connected(
assert evaluator._dispatchers_empty.is_set()


@pytest.mark.integration_test
async def test_evaluator_raises_on_start_with_address_in_use(make_ee_config):
ee_config = make_ee_config(use_ipc_protocol=False)
ctx = zmq.asyncio.Context()
Expand All @@ -109,7 +108,8 @@ async def test_evaluator_raises_on_start_with_address_in_use(make_ee_config):
with pytest.raises(zmq.error.ZMQError, match="Address already in use"):
await evaluator.run_and_get_successful_realizations()
finally:
ctx.destroy()
socket.close()
ctx.destroy(linger=0)


async def test_no_config_raises_valueerror_when_running():
Expand Down

0 comments on commit 7e600dd

Please sign in to comment.