How do I disable the error logger in EUnit test cases? - erlang

When running an EUnit test that tests an application or starts and stops (or tests killing of) gen_server or supervisor processs, error logger outputs crash reports and other messages by default:
$ rebar3 eunit 1s
===> Verifying dependencies...
===> Compiling my_app
===> Performing EUnit tests...
...........=INFO REPORT==== 5-Sep-2019::16:32:18.760457 ===
application: ranch
exited: stopped
type: temporary
=INFO REPORT==== 5-Sep-2019::16:32:18.760545 ===
application: xmerl
exited: stopped
type: temporary
=INFO REPORT==== 5-Sep-2019::16:32:18.763882 ===
application: my_app
exited: stopped
type: temporary
......=ERROR REPORT==== 5-Sep-2019::16:32:18.814431 ===
** Generic server my_app_sup terminating
** Last message in was {'EXIT',<0.279.0>,test_kill}
** When Server state == {state,
{local,my_app_sup},
simple_one_for_one,
{[undefined],
#{undefined =>
{child,undefined,undefined,
{my_app_server,start_link,[]},
transient,5000,worker,
[my_app_server]}}},
{maps,#{<0.355.0> => [my_app_test]}},
1,5,[],0,my_app_sup,[]}
** Reason for termination ==
** test_kill
=CRASH REPORT==== 5-Sep-2019::16:32:18.814598 ===
crasher:
initial call: supervisor:my_app_sup/1
pid: <0.354.0>
registered_name: my_app_sup
exception exit: test_kill
in function gen_server:decode_msg/9 (gen_server.erl, line 432)
ancestors: [<0.279.0>]
message_queue_len: 0
messages: []
links: []
dictionary: []
trap_exit: true
status: running
heap_size: 1598
stack_size: 27
reductions: 6463
neighbours:
...........
Finished in 0.457 seconds
28 tests, 0 failures
How can I avoid these expected messages during testing?

These can be avoided by temporarily disabling TTY reports in the error logger. Surround the code which produces the reports with this:
my_test() ->
error_logger:tty(false),
try
% code that produces error logger reports
after
error_logger:tty(true)
end.
If you use this many times in the tests, this wrapper can be useful:
without_error_logger(Fun) ->
error_logger:tty(false),
try
Fun()
after
error_logger:tty(true)
end.
Which is used like so:
without_error_logger(fun() ->
% code that produces error logger reports
end)

Related

Deploying Elixir Docker to Heroku. Can't set long node name

I'm trying to deploy a Dockerfile to Heroku and when the app starts, it immediately crashes with this error:
=INFO REPORT==== 2-Apr-2022::16:20:30.959748 ===
Can't set long node name!
Please check your configuration
=SUPERVISOR REPORT==== 2-Apr-2022::16:20:30.960208 ===
supervisor: {local,net_sup}
errorContext: start_error
reason: {'EXIT',nodistribution}
offender: [{pid,undefined},
{id,net_kernel},
{mfargs,{net_kernel,start_link,
[[api#,longnames],true,net_sup]}},
{restart_type,permanent},
{significant,false},
{shutdown,2000},
{child_type,worker}]
=CRASH REPORT==== 2-Apr-2022::16:20:30.960246 ===
crasher:
initial call: net_kernel:init/1
pid: <0.3363.0>
registered_name: []
exception exit: {error,badarg}
in function gen_server:init_it/6 (gen_server.erl, line 407)
ancestors: [net_sup,kernel_sup,<0.3349.0>]
message_queue_len: 0
messages: []
links: [<0.3360.0>]
dictionary: [{longnames,true}]
trap_exit: true
status: running
heap_size: 987
stack_size: 28
reductions: 770
neighbours:
=SUPERVISOR REPORT==== 2-Apr-2022::16:20:30.963246 ===
supervisor: {local,kernel_sup}
errorContext: start_error
reason: {shutdown,
{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}
offender: [{pid,undefined},
{id,net_sup},
{mfargs,{erl_distribution,start_link,[]}},
{restart_type,permanent},
{significant,false},
{shutdown,infinity},
{child_type,supervisor}]
=CRASH REPORT==== 2-Apr-2022::16:20:30.966821 ===
crasher:
initial call: application_master:init/4
pid: <0.3348.0>
registered_name: []
exception exit: {{shutdown,
{failed_to_start_child,net_sup,
{shutdown,
{failed_to_start_child,net_kernel,
{'EXIT',nodistribution}}}}},
{kernel,start,[normal,[]]}}
in function application_master:init/4 (application_master.erl, line 142)
ancestors: [<0.3347.0>]
message_queue_len: 1
messages: [{'EXIT',<0.3349.0>,normal}]
links: [<0.3347.0>,<0.3346.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 610
stack_size: 28
reductions: 165
neighbours:
=INFO REPORT==== 2-Apr-2022::16:20:30.967283 ===
application: kernel
exited: {{shutdown,
{failed_to_start_child,net_sup,
{shutdown,
{failed_to_start_child,net_kernel,
{'EXIT',nodistribution}}}}},
{kernel,start,[normal,[]]}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,net_kernel,{'EXIT',nodistribution}}}}},{ker
Crash dump is being written to: erl_crash.dump...done
Process exited with status 1
State changed from starting to crashed
Let me know if theres specific info you need to help me narrow the problem down.
Anyone have any ideas?
I had a rel/env.sh.eex file that was setting
export RELEASE_DISTRIBUTION=name
export RELEASE_NODE=api#${POD_IP}
where POD_IP was not set, causing the error.
You should check your pc's os hostname. It should contain ".",otherwise long name can't be used.

RabbitMQ crashed and remained in hung state

One of the RabbitMQ nodes went down but remained in hung state which didn't let the other node to become active node. Have a VIP through which applications connect to Rabbit, in case one of the nodes go down the VIP switches to the other node but this didn't happen as the first node, that went down, hung itself.
Below are the logs from that time.
[Then Active Node that hung]
=CRASH REPORT==== 11-Jun-2017::05:15:09 ===
crasher:
initial call: rabbit_disk_monitor:init/1
pid: <0.253.0>
registered_name: rabbit_disk_monitor
exception exit: {eagain,[{erlang,open_port,
[{spawn,"/bin/sh -s unix:cmd 2>&1"},
[stream]],
[]},
{os,start_port_srv_handle,1,
[{file,"os.erl"},{line,313}]},
{os,start_port_srv_loop,0,
[{file,"os.erl"},{line,329}]}]}
in function gen_server:terminate/7 (gen_server.erl, line 826)
ancestors: [rabbit_disk_monitor_sup,rabbit_sup,<0.243.0>]
messages: []
links: [<0.252.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 1598
stack_size: 27
reductions: 2036096302
neighbours:
[The other node which should have taken over]
=CRASH REPORT==== 11-Jun-2017::05:15:09 ===
crasher:
initial call: rabbit_disk_monitor:init/1
pid: <0.253.0>
registered_name: rabbit_disk_monitor
exception exit: {eagain,[{erlang,open_port,
[{spawn,"/bin/sh -s unix:cmd 2>&1"},
[stream]],
[]},
{os,start_port_srv_handle,1,
[{file,"os.erl"},{line,313}]},
{os,start_port_srv_loop,0,
[{file,"os.erl"},{line,329}]}]}
in function gen_server:terminate/7 (gen_server.erl, line 826)
ancestors: [rabbit_disk_monitor_sup,rabbit_sup,<0.243.0>]
messages: []
links: [<0.252.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 1598
stack_size: 27
reductions: 2036096302
neighbours:
Could, using delayed message plugin and mnesia have caused this?
eagain means Resource temporarily unavailable
Most likely you ran out the filedescriptors.
Check your current filedescription configuration and try to increase it
Check this links for more details:
debian: http://www.rabbitmq.com/install-debian.html#kernel-resource-limits
RPM http://www.rabbitmq.com/install-rpm.html#kernel-resource-limits

bad argument in call to fxml_stream:new(undefined, 65536)

I am not familiar with erlang and new to ejabberd. I am getting following
error in crash.log.
2017-06-22 04:58:53 =CRASH REPORT====
crasher:
initial call: ejabberd_receiver:init/1
pid: <0.23584.370>
registered_name: []
exception exit: {{badarg,[{fxml_stream,new,[undefined,65536],[]},{ejabberd_receiver,handle_call,3,[{file,"src/ejabberd_receiver.erl"},{line,168}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,615}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,647}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]},[{gen_server,terminate,7,[{file,"gen_server.erl"},{line,812}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
ancestors: [<0.358.0>,ejabberd_listener,ejabberd_sup,<0.62.0>]
messages: []
links: []
dictionary: []
trap_exit: false
status: running
heap_size: 610
stack_size: 27
reductions: 275
neighbours:
2017-06-22 07:05:00 =ERROR REPORT====
** Generic server <0.25047.377> terminating
** Last message in was {become_controller,undefined}
** When Server state == {state,#Port<0.5706277>,gen_tcp,none,undefined,65536,undefined,infinity}
** Reason for termination ==
** {badarg,[{fxml_stream,new,[undefined,65536],[]},{ejabberd_receiver,handle_call,3,[{file,"src/ejabberd_receiver.erl"},{line,168}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,615}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,647}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
Can anybody help me understand the issue here?
There is the corresponding issue in the bugtracker which is already fixed.

RabbitMQ/Erlang crashing: Cannot reallocate 313760 bytes of memory (of type "code")

Can anyone please help to understand these crash logs?
RabbitMQ 3.6.6, Erlang 19.1
RabbitMQ is running on Microsoft Windows Web Server 2008 R2 6.1.7601 Service Pack 1 Build 7601 64bit.
RabbitMQ started to crash yesterday after running OK about one year. Now I have upgraded Erlang and RabbitMQ Server to the versions mentioned above but this did not change anything - still crashing
frequently.
.log:
=ERROR REPORT==== 13-Dec-2016::22:13:55 ===
** Generic server rabbit_disk_monitor terminating
** Last message in was update
** When Server state == {state,"d:/ETOIMI~1/RabbitMQ/RABBIT~1",50000000,
14439952384,100,10000,#Ref<0.0.1.27257>,false,
true}
** Reason for termination ==
** {eacces,[{erlang,open_port,
[{spawn,"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},
{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,165}]},
{gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
-sasl.log:
=CRASH REPORT==== 13-Dec-2016::22:13:55 ===
crasher:
initial call: rabbit_disk_monitor:init/1
pid: <0.211.0>
registered_name: rabbit_disk_monitor
exception exit: {eacces,
[{erlang,open_port,
[{spawn,
"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},
{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,165}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
in function gen_server:terminate/7 (gen_server.erl, line 812)
ancestors: [rabbit_disk_monitor_sup,rabbit_sup,<0.164.0>]
messages: []
links: [<0.210.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 6772
stack_size: 27
reductions: 381464
neighbours:
=SUPERVISOR REPORT==== 13-Dec-2016::22:13:55 ===
Supervisor: {local,rabbit_disk_monitor_sup}
Context: child_terminated
Reason: {eacces,
[{erlang,open_port,
[{spawn,
"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},{line,165}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
Offender: [{pid,<0.211.0>},
{name,rabbit_disk_monitor},
{mfargs,{rabbit_disk_monitor,start_link,[50000000]}},
{restart_type,{transient,1}},
{shutdown,30000},
{child_type,worker}]
Also I have found Erlang crash dump, please see
HERE
If there is more information that should be provided by me please let me know.
Thank you!
** {eacces,[{erlang,open_port,
[{spawn,"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
eacces is an Erlang error:
eacces Missing search or write permissions for the parent directories
of Dir.
most likely the service has problems to access here: d:/ETOIMI~1/RabbitMQ/RABBIT~1\

Erlang sellaprime OTP application

I'm trying to run the sellaprime example OTP application from Chapter 23 of Programming Erlang 2nd Ed. I have uploaded the code to https://github.com/myles-mcdonnell/sellaprime
After compiling with rebar I run erl from the root, then switch dir ..
1> c(src).
/Users/mylesmcdonnell/sellaprime/src
ok
then I load the app..
2> application:load(sellaprime).
ok
then I try to start the app..
3> application:start(sellaprime).
=CRASH REPORT==== 5-Feb-2015::09:55:34 ===
crasher:
initial call: application_master:init/4
pid: <0.48.0>
registered_name: []
exception exit: {bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},
{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},
{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},
{line,294}]}]}}}}
in function application_master:init/4 (application_master.erl, line 133)
ancestors: [<0.47.0>]
messages: [{'EXIT',<0.49.0>,normal}]
links: [<0.47.0>,<0.7.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 610
stack_size: 27
reductions: 124
neighbours:
=INFO REPORT==== 5-Feb-2015::09:55:34 ===
application: sellaprime
exited: {bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},
{line,294}]}]}}}}
type: temporary
{error,
{bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},{line,294}]}]}}}}}
Clearly something is undefined but I'm struggling to determine what? I have lifted the code directly from the book download site with no changes.

Resources