diff --git a/lib/live_book/runtime/erl_dist/manager.ex b/lib/live_book/runtime/erl_dist/manager.ex index 37c7f3513..aaa2939fb 100644 --- a/lib/live_book/runtime/erl_dist/manager.ex +++ b/lib/live_book/runtime/erl_dist/manager.ex @@ -93,11 +93,22 @@ defmodule LiveBook.Runtime.ErlDist.Manager do Process.send_after(self(), :check_owner, @await_owner_timeout) - {:ok, %{owner: nil, evaluators: %{}}} + # Set `ignore_module_conflict` only for the Manager lifetime. + initial_ignore_module_conflict = Code.compiler_options()[:ignore_module_conflict] + Code.compiler_options(ignore_module_conflict: true) + + {:ok, + %{ + owner: nil, + evaluators: %{}, + initial_ignore_module_conflict: initial_ignore_module_conflict + }} end @impl true - def terminate(_reason, _state) do + def terminate(_reason, state) do + Code.compiler_options(ignore_module_conflict: state.initial_ignore_module_conflict) + ErlDist.unload_required_modules() :ok diff --git a/test/live_book/runtime/erl_dist/manager_test.exs b/test/live_book/runtime/erl_dist/manager_test.exs index 649232476..a21794647 100644 --- a/test/live_book/runtime/erl_dist/manager_test.exs +++ b/test/live_book/runtime/erl_dist/manager_test.exs @@ -38,5 +38,23 @@ defmodule LiveBook.Runtime.ErlDist.ManagerTest do Manager.stop(node()) end + + test "prevents from module redefinition warning being printed to standard error" do + Manager.start() + Manager.set_owner(node(), self()) + + stderr = + ExUnit.CaptureIO.capture_io(:stderr, fn -> + Manager.evaluate_code(node(), "defmodule Foo do end", :container1, :evaluation1) + Manager.evaluate_code(node(), "defmodule Foo do end", :container1, :evaluation2) + + assert_receive {:evaluation_response, :evaluation1, _} + assert_receive {:evaluation_response, :evaluation2, _} + end) + + assert stderr == "" + + Manager.stop(node()) + end end end