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.
This commit is contained in:
Linus 2023-01-23 22:14:40 +01:00 committed by GitHub
parent f5dbc2de9f
commit 9f3ea5856a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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