From 9f3ea5856abad6e497cb512076400960a30504e5 Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 23 Jan 2023 22:14:40 +0100 Subject: [PATCH] Check attached node elixir version (#1654) The attached node should have a minimum elixir version, to avoid problems at runtime. For example, Livebook version 0.8 introduced a dependency on `Code.eval_quoted_with_env/4` which is new since elixir 1.14.2. --- lib/livebook/runtime/attached.ex | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/livebook/runtime/attached.ex b/lib/livebook/runtime/attached.ex index bf58dd45f..1ed4b2bd9 100644 --- a/lib/livebook/runtime/attached.ex +++ b/lib/livebook/runtime/attached.ex @@ -39,17 +39,30 @@ defmodule Livebook.Runtime.Attached do # Set cookie for connecting to this specific node Node.set_cookie(node, cookie) - case Node.ping(node) do - :pong -> - server_pid = - Livebook.Runtime.ErlDist.initialize(node, - node_manager_opts: [parent_node: node(), capture_orphan_logs: false] - ) + with :pong <- Node.ping(node), + :ok <- check_attached_node_version(node) do + server_pid = + Livebook.Runtime.ErlDist.initialize(node, + node_manager_opts: [parent_node: node(), capture_orphan_logs: false] + ) - {:ok, %{runtime | node: node, server_pid: server_pid}} + {:ok, %{runtime | node: node, server_pid: server_pid}} + else + :pang -> {:error, "node #{inspect(node)} is unreachable"} + {:error, msg} -> {:error, msg} + end + end - :pang -> - {:error, "node #{inspect(node)} is unreachable"} + @elixir_version_requirement Keyword.fetch!(Mix.Project.config(), :elixir) + + defp check_attached_node_version(node) do + attached_node_version = :erpc.call(node, System, :version, []) + + if Version.match?(attached_node_version, @elixir_version_requirement) do + :ok + else + {:error, + "the node uses Elixir #{attached_node_version}, but #{@elixir_version_requirement} is required"} end end