noelob

noelob

Error Spawning Process on Another Node

Hi,

I’ve created a simple cluster by opening 2 IEX sessions on two different machines, and I can see the the nodes are clustered:

iex(dev@127.0.0.1)11> Node.list [:this, :visible]
[:"suv@127.0.0.1", :"dev@127.0.0.1"]

When I try running a simple process on the other node, I get this error:

 iex(dev@127.0.0.1)7> caller = self()
 #PID<0.115.0>
 iex(dev@127.0.0.1)8> Node.spawn(:"suv@127.0.0.1", fn -> send(caller, {:response, 1+2}) end)
 #PID<14963.130.0>
 
 11:43:45.064 [error] Process #PID<14963.130.0> on node :"suv@127.0.0.1" raised an exception
 ** (BadFunctionError) function #Function<43.125776118/0 in :erl_eval.expr/6> is invalid, likely because it points to an old version of the code
     :erlang.apply/2
 iex(dev@127.0.0.1)9> nil

The error implies :erl_eval.expr/6 is missing, so my first guess was differing versions of Elixir and/or Erlang/OTP on each node, but both have elixir 1.15 and OPT 26 as far as I can tell:

Node A:

iex(dev@127.0.0.1)6> System.build_info 
%{
   version: "1.15.5",
   date: "2023-08-28T11:58:30Z",
   otp_release: "26",
   build: "1.15.5 (compiled with Erlang/OTP 26)",
   revision: "9fd97c4" 
}

Node B:

 iex(suv@127.0.0.1)15> System.build_info
 %{
   version: "1.15.8",
   date: "2024-11-12T06:54:38Z",
   otp_release: "26",
   build: "1.15.8 (compiled with Erlang/OTP 26)",
   revision: ""
 }

When I use tab completion on :erl_eval.expr in IEX there is no :erl_eval.expr/6. Any idea what I might be doing wrong?

Marked As Solved

ruslandoga

ruslandoga

:wave:

What happens if you try

Node.spawn(:"suv@127.0.0.1", Kernel, :send, [caller, {:response, 1+2}])

?

Re erl_eval in #Function<43.125776118/0 in :erl_eval.expr/6> I think it just means that the anonymous function was defined in IEx. It might or might not mean that erl_eval is the problem. It might as well be Kernel.send/1, if that module / function were updated between 1.15.5 and 1.15.8, which they probably were, at least in “version”.

Also Liked

ruslandoga

ruslandoga

When spawning a remote process like this, does the ‘work’ (1+2 in this case) get evaluated on the local node?

Arguments (it’s just a normal list) are “evaluated” on the calling node, the function is executed on the remote node.

It’s the same as:

iex(dev@127.0.0.1)> caller = self()
iex(dev@127.0.0.1)> args = [caller, {:response, Node.self}]
#==> [#PID<0.114.0>, {:response, :"dev@127.0.0.1"}]

iex(dev@127.0.0.1)> Node.spawn(:"suv@127.0.0.1", Kernel, :send, args)
iex(dev@127.0.0.1)> flush()
#==> {:response, :"dev@127.0.0.1)"}

You can make the called function process its args and then that part would be handled by the remote node too:

iex(suv@127.0.0.1)> defmodule Worker do
                      def do_work, do: {:response, Node.self()}
                    end

iex(suv@127.0.0.1)> Worker.do_work()
#==> {:response, :"suv@127.0.0.1)"}

# -------------------- back to dev@127.0.0.1 -------------------------

iex(dev@127.0.0.1)> :erpc.call(:"suv@127.0.0.1", Worker, :do_work, [])
#==> {:response, :"suv@127.0.0.1)"}

:erpc.call here just executes the function remotely and sends back the results, similar to your Node.spawn example with send. I just wanted to mention it as it’s a pretty useful module.

ruslandoga

ruslandoga

I would guess that the closures capture module versions (MD5 by default) in addition to module and function names and since they are different in different versions of Elixir, it results in an error. And maybe sending Node.spawn(:"suv@127.0.0.1", Kernel, :send, [caller, {:response, 1+2}]) doesn’t concern itself with module versions and just runs apply(Kernel, :send, [caller, {:response, 1+2}]) so it works across Elixir versions. But it can possibly produce different results from if this was executed locally. But I guess that’s usually expected with distributed systems.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement