net_kernel:start fails with `{'EXIT',nodistribution}` - erlang

I faced with a problem and hope that someone can help me.
I try to start net_kernel by :
net_kernel:start([test,shortnames]).
But I faced with this error :
{error,
{{shutdown,
{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}},
{child,undefined,net_sup_dynamic,
{erl_distribution,start_link,[[test,shortnames]]},
permanent,1000,supervisor,
[erl_distribution]}}}
=INFO REPORT==== 23-Apr-2017::21:07:43 ===
Protocol: "inet_tcp": register/listen error: econnrefused
Amazing tip is that when trying to start net_kernel by:
erl -sname test
net_kernel will start successfully
and another amazing tip is that after start net_kernel at least one time after OS boot and exit erl shell , the first way to start net_kernel will work successfully :|
( net_kernel:start([...]) )
after some search I found that CouchBase and RabbitMQ-Server and Ejabberd and some other apps that uses erlang , reported this error ( nodistribution error )

You have no epmd running, that'll be what the econnrefused is about. When you start net_kernel it wants to register a name with epmd so the node is findable.
Make sure there is an epmd process running at the time you start net_kernel and I bet the problem goes away.
Regarding erl -sname test working, I expect that starts epmd for you?

Related

Docker Desktop not starting

Docker desktop was working fine but after a reboot the docker desktop doesn't start at all.
I've tried switchDaemon, Switch to Windows container etc., but none of them starts.
I'm using WSL2 and all my containers are linux based. If I re-install then I'll lose all data and images.
wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
docker-desktop
docker-desktop-data
Every restart attempt results with the following log entires.
open \\.\pipe\dockerProcd: The system cannot find the file specified.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Log:
[2022-08-01T14:09:47.861542400Z][com.docker.backend.exe][I] (15e5c8d5) 4b373d33-BackendAPI S->C DockerDesktopElectron POST /nps (1.6312ms): OK
[2022-08-01T14:09:50.286711200Z][com.docker.backend.exe][I] (e474d45c) 4b373d33-BackendAPI S<-C DockerDesktopElectron POST /analytics/track
[2022-08-01T14:09:50.287235200Z][com.docker.backend.exe][I] (e474d45c) 4b373d33-BackendAPI S<-C DockerDesktopElectron bind: {"body":null,"event":"actionMenuSwitchWindowsDaemon"}
[2022-08-01T14:09:50.287758600Z][com.docker.backend.exe][I] (e474d45c) 4b373d33-BackendAPI S->C DockerDesktopElectron POST /analytics/track (1.0474ms): OK
[2022-08-01T14:09:50.288277300Z][com.docker.backend.exe][I] Usage statistics: actionMenuSwitchWindowsDaemon
[2022-08-01T14:09:50.288277300Z][com.docker.backend.exe][I] anonymous remaining time: 23h35m58.7117227s
[2022-08-01T14:09:51.767785100Z][IPCServer ][Info ] (3f58fd7b) acc5d626-CSharpAPI S<-C DockerDesktopElectron POST /desktop/switch-engine
[2022-08-01T14:09:51.773786400Z][IPCServer ][Info ] (3f58fd7b) acc5d626-CSharpAPI S->C DockerDesktopElectron POST /desktop/switch-engine (6ms): OK
[2022-08-01T14:09:53.056235800Z][WslKeepAlive ][Info ] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
[2022-08-01T14:09:53.059234500Z][WslKeepAlive ][Info ] wsl keep-alive stopped
[2022-08-01T14:09:53.059234500Z][WslKeepAlive ][Warning] stopped unexpectedly
[2022-08-01T14:09:53.244964600Z][vpnkit-bridge.exe][W] windows: still waiting for dns-forwarder, volume-contents, lifecycle-server, wsl2-bootstrap-expose-ports, devenv-volumes, procd, docker, debug-shell, diagnosticd, wsl2-cross-distro-service, log after 10.01406s
[2022-08-01T14:10:03.238970300Z][vpnkit-bridge.exe][W] windows: still waiting for dns-forwarder, volume-contents, lifecycle-server, wsl2-bootstrap-expose-ports, devenv-volumes, procd, docker, debug-shell, diagnosticd, wsl2-cross-distro-service, log after 20.0080657s
[2022-08-01T14:10:05.610766100Z][com.docker.backend.exe][W] 526c5971-PauseHDL /pause/events server not replying: Get "http://ipc/pause/events": open \\.\pipe\dockerProcd: The system cannot find the file specified.
[2022-08-01T14:10:13.241610100Z][vpnkit-bridge.exe][W] windows: still waiting for lifecycle-server, wsl2-bootstrap-expose-ports, devenv-volumes, procd, docker, dns-forwarder, volume-contents, wsl2-cross-distro-service, log, debug-shell, diagnosticd after 30.0105872s

Erlang: starting gen_server on another node fails after init

I am stuck in a bit of a fix trying to run gen_server on another node. So I have a common gen_server class which looks like this
start(FileName) ->
start_link(node(), FileName).
start_link(ThisNode, FileName) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [ThisNode, FileName], []).
init([ThisNode, FileName]) ->
process_flag(trap_exit, true),
{ok, Terms} = file:consult(FileName),
{A1, B1, C1} = lists:nth(1,Terms),
place_objects(A1, B1, C1).
Now I want to start multiple nodes that will run the same gen_server and somehow communicate with each other, and use a another node to orchestrate that. (All these nodes are started on my local terminal).
So I start a new node in one terminal using erl -sname bar where I intend to run the gen_server, and compile the gen_server module on this node. Then I start another node called 'sup' which I intend to use as a coordinator for all the other nodes. If I run the command my_gen_server:start("config_bar.txt"). on bar, it successfully returns but when I run the command rpc:call('bar#My-MacBook-Pro', my_gen_server, start, ["config_bar.txt"]). on sup, it successfully returns from the init method (I checked this by putting in the logs) but immediately after that, I get this error:
{ok,<9098.166.0>}
(sup#My-MacBook-Pro)2> =ERROR REPORT==== 21-Feb-2022::11:12:30.443051 ===
** Generic server my_gen_server terminating
** Last message in was {'EXIT',<9098.165.0>,
{#Ref<0.3564861827.2990800899.137513>,return,
{ok,<9098.166.0>}}}
** When Server state == {10,10,#Ref<9098.1313723616.3973185546.82660>,
'bar#My-MacBook-Pro'}
** Reason for termination ==
** {#Ref<0.3564861827.2990800899.137513>,return,{ok,<9098.166.0>}}
=CRASH REPORT==== 21-Feb-2022::11:12:30.443074 ===
crasher:
initial call: my_gen_server:init/1
pid: <9098.166.0>
registered_name: my_gen_server
exception exit: {#Ref<0.3564861827.2990800899.137513>,return,
{ok,<9098.166.0>}}
in function gen_server:decode_msg/9 (gen_server.erl, line 481)
ancestors: [<9098.165.0>]
message_queue_len: 0
messages: []
links: []
dictionary: []
trap_exit: true
status: running
heap_size: 1598
stack_size: 29
reductions: 3483
neighbours:
I can't seem to figure out what causes the error and if there's anything I need to add to my gen_server code to fix it. Would really appreciate some help on this one!
The gen_server in the remote node is linked to an ephemeral process created for the rpc call.
As this ephemeral process exits with a term that's different from normal (the actual result of the rpc call), the exit signal propagates to the gen_server, killing it.
You can use gen_server:start instead of gen_server:start_link or, if you want the gen_server to be part of the supervission tree, instruct its supervisor to spawn it:
rpc:call('bar#My-MacBook-Pro', my_gen_sup, start_child, ["config_bar.txt"]).

Call Python function from Erlang Code

I am working on MQTT broker (http://www.emqtt.io), which is written in Erlang. I have a use case where I need to call one of my python module from emqtt broker code written in erlang.
I have already checked into the google about erlport (http://erlport.org/) which is use for port communication between erlang and python. It works well in erlang shell but when I use the same in emqtt erlang code then it does not work. It throws an error shown below
17:22:40.073 <0.717.0> [error] gen_server <0.717.0> terminated with reason: call to undefined function python:start()
17:22:40.073 <0.717.0> [error] CRASH REPORT Process <0.717.0> with 1 neighbours exited with reason: call to undefined function python:start() in gen_server2:terminate/3 line 1151
17:22:40.073 <0.631.0> [error] Supervisor emqttd_session_sup had child session started with {emqttd_session,start_link,undefined} at <0.717.0> exit with reason call to undefined function python:start() in context child_terminated
17:22:40.073 <0.677.0> [error] Supervisor 'esockd_connection_sup - <0.677.0>' had child connection started with emqttd_client:start_link([{packet,[{max_clientid_len,512},{max_packet_size,65536}]},{client,[{idle_timeout,30}]},{session,...},...]) at <0.716.0> exit with reason call to undefined function python:start() in context connection_crashed
We are calling python module from emqtt plugins code, change of code is show below
on_message_acked(ClientId, Message, _Env) ->
io:format("client ~s acked: ~s~n", [ClientId, emqttd_message:format(Message)]),
io:format("client ~s",[python:start()]),
{ok, Message}.
Please help us.

Can't start supervisor from yaws runmod

I have a yaws runmod defined in yaws.conf as:
runmod = sg_app
the module contains an exported function:
start()->
io:format("~p start~n", [ sg_sup:start_link() ]).
When I start yaws I see a call to the runmod:
=INFO REPORT==== 29-Oct-2015::16:46:51 === sync call sg_app:start
{ok,<0.61.0>} start
But the supervisor is nonexistent:
1> whereis(sg_sup).
undefined
If I call the runmod:start manually, the supervisor hangs around.
2> sg_app:start().
{ok,<0.73.0>} start
ok
3> whereis(sg_sup).
<0.73.0>
What have I done wrong?
Your runmod's start/0 function is starting the supervisor with start_link/0, which means it's getting linked to the parent process. When that process dies, it takes your runmod process down with it, due to the link. The runmod feature isn't designed for starting a supervision tree.
You might instead consider using a yapp, which allows your code to run as a regular Erlang application in the same Erlang node as Yaws and be registered to have Yaws dispatch requests into it.
Another option is to launch your application using a separately spawned, infinite process:
start()->
spawn(fun () ->
application:start(my_app, permanent),
receive after infinity -> ok end
end).

How to start Inets httpd server?

I try to start Inets httpd server and have some documents in the document_root, but I can not start up the server. How can I start it?
This is the config I start it with:
>{ok, Pid} = inets:start(httpd, [{port, 8070}, {server_name, "myhttpd"},
>{server_root, "/Users/jonas/code"},
>{document_root, "/Users/jonas/code/mydocs"},
>{bind_address, "localhost"}]).
** exception error: no match of right hand side value {error, inets_not_started}
You should first call inets:start/0.

Resources