Exception when running Erlang Cowboy web server in Mac OS X - macos

I'm trying to run a Cowboy web server in Mac OS X 1.9 and I'm getting a stack trace. On a ubuntu box everything runs fine, so I believe this must be something simple to fix if anybody has experienced the problem.
The command:
./_rel/bin/cowfarm command
The stack trace:
Exec: /Users/marcosvm/code/spikes/cowfarm/_rel/erts-5.10.2/bin/erlexec -boot /Users/marcosvm/code/spikes/cowfarm/_rel/releases/1/cowfarm -mode embedded -config /Users/marcosvm/code/spikes/cowfarm/_rel/releases/1/sys.config -args_file /Users/marcosvm/code/spikes/cowfarm/_rel/releases/1/vm.args -- console
Root: /Users/marcosvm/code/spikes/cowfarm/_rel
Erlang R16B01 (erts-5.10.2) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
=INFO REPORT==== 26-Nov-2013::15:08:49 ===
application: cowboy
exited: {bad_return,
{{cowboy_app,start,[normal,[]]},
{'EXIT',
{undef,
[{cowboy_app,start,[normal,[]],[]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,269}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,cowboy,{bad_return,{{cowboy_app,start,[normal,[]]},{'EXIT',{undef,[{cowboy_app,start,[normal,[]],[]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,269}]}]}}}}}"}
Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,cowboy,{bad_return,{{cowboy_app,start,[normal,[]]},{'EXIT',{undef,[{cowboy_app,start,[normal,[]],[]},{application_master,st

The cowboy application is not in the path:
...
{undef,
[{cowboy_app,start,[normal,[]],[]},
...
maybe you should start the application from another place, or add the path to the cowboy application adding "-pa path/to/cowboy/ebin" where you are calling the erlang vm

Related

Cowboy webserver crashes on startup after adding ibrowse dependency to Makefile

I'm currently developing a server in Erlang using Cowboy as the web server framework. At startup, I need to be able to make server-side HTTP calls to fetch files from other web servers, so I've included a Makefile dependency to ibrowse
The ibrowse documentation does not mention anything specifically about being added as a Cowboy dependency, but the erlang.mk documentation indicates that I only need to add the single line
DEPS = ibrowse
However, as soon as I add this line, Cowboy crashes on startup with
=INFO REPORT==== 15-Feb-2018::14:51:13 ===
application: geo_server
exited: {bad_return,
{{geo_server_app,start,[normal,[]]},
{'EXIT',
{undef,
[{cowboy_router,compile,
[[{'_',
[{"/",default_handler,[]},
{"/client_info",client_info_handler,[]},
{"/search",request_handler,[]}]}]],
[]},
{geo_server_app,start,2,
[{file,"src/geo_server_app.erl"},{line,8}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,273}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,geo_server,{bad_return,{{geo_server_app,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{\"/\",default_handler,[]},{\"/client_info\",client_info_handler,[]},{\"/search\",request_handler,[]}]}]],[]},{geo_server_app,start,2,[{file,\"src/geo_server_app.erl\"},{line,8}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,273}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,geo_server,{bad_return,{{geo_server_app,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{"/",default_handle
heart: Thu Feb 15 14:51:14 2018: Erlang is crashing .. (waiting for crash dump file)
heart: Thu Feb 15 14:51:14 2018: Would reboot. Terminating.
gmake: *** [erlang.mk:6639: run] Error 1
Take this dependency away, and Cowboy starts up fine.
PROJECT = geo_server
PROJECT_DESCRIPTION = Geographic information server
PROJECT_VERSION = 0.1.0
DEPS = cowboy
dep_cowboy_commit = 2.2.2
DEP_PLUGINS = cowboy
include erlang.mk
DEPS = ibrowse
It also doesn't matter whether I put the DEPS = ibrowse before or after the line include elrang.mk.
After some more noodling around, this seems to a caching problem in the way Cowboy's make run process works.
Adding ibrowse seems to require two calls to make run. If my code then crashes, I have to add and then remove ibrowse again before I can see my amended code running.
Thanks
Chris W
From erlang.mk documentation
DEPS List of applications this project depends on that need to be
fetched by Erlang.mk.
Solution:
DEPS = cowboy ibrowse
The DEPS need only occur once and contains a space separated list of dependencies

Cannot start riak: "Failed to load erlang_js_drv.so"

I have been trying to get riak running on a macbook, following the official guide
I have tried pulling the tarball and also installing from source. The result is the same
here is the output from riak console:
config is OK
-config /Users/jistone/riak-2.0.4/rel/riak/data/generated.configs/app.2015.02.16.22.22.49.config -args_file /Users/jistone/riak-2.0.4/rel/riak/data/generated.configs/vm.2015.02.16.22.22.49.args -vm_args /Users/jistone/riak-2.0.4/rel/riak/data/generated.configs/vm.2015.02.16.22.22.49.args
!!!!
!!!! WARNING: ulimit -n is 256; 65536 is the recommended minimum.
!!!!
Exec: /Users/jistone/riak-2.0.4/rel/riak/bin/../erts-5.10.3/bin/erlexec -boot /Users/jistone/riak-2.0.4/rel/riak/bin/../releases/2.0.4/riak -config /Users/jistone/riak-2.0.4/rel/riak/data/generated.configs/app.2015.02.16.22.22.49.config -args_file /Users/jistone/riak-2.0.4/rel/riak/data/generated.configs/vm.2015.02.16.22.22.49.args -vm_args /Users/jistone/erlang/rktar/riak-2.0.4/rel/riak/data/generated.configs/vm.2015.02.16.22.22.49.args -pa /Users/jistone/riak-2.0.4/rel/riak/bin/../lib/basho-patches -- console
Root: /Users/jistone/riak-2.0.4/rel/riak/bin/..
Erlang R16B02-basho5 (erts-5.10.3) [source] [smp:8:8] [async-threads:64] [hipe] [kernel-poll:true]
{"Kernel pid terminated",application_controller,"{application_start_failure,erlang_js,{{bad_return_value,{error,{load_error,\"Failed to load erlang_js_drv.so\"}}},{erlang_js,start,[normal,[]]}}}"}
Crash dump was written to: ./log/erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,erlang_js,{{bad_return_value,{error,{load_error,"Failed to load erlang_js_drv.so"}}},{erlang_js,start,[normal,[]]}}})
erlang_js_drv.so does exist:
$ find ./ -name erlang_js_drv.so
.//lib/erlang_js-1.3.0-0-g07467d8/priv/erlang_js_drv.so
So I'm not sure what the message is about. How can I debug this further?

Yaws process died: {{badmatch,<<>>}

I'm going over a very basic erlang book while using yaws. I'm editing a single yaws file and refreshing the browser. Often (3rd time now) the process will just start to show this error. and i look and look for a syntax error or anything, and eventually i just restart the process and everything works. without any change to the source file.
right now this is the source file that triggered the error this last time
<erl>
out(Arg) ->
{ehtml,
{table, [{width, "100%"}],
{tr,[],
[{td, [{width, "50%"}], "hello world!"},
{td, [{width, "50%"}], "hi again."}]
}
}
}.
</erl>
I tried searching the error, but where all the search results have a meaningful context like "no access" all i get is "<<>>"
=ERROR REPORT==== 26-Nov-2013::20:17:32 ===
Yaws process died: {{badmatch,<<>>},
[{yaws_server,skip_data,2,
[{file,"yaws_server.erl"},{line,2951}]},
{yaws_server,deliver_dyn_file,6,
[{file,"yaws_server.erl"},{line,2717}]},
{yaws_server,aloop,4,
[{file,"yaws_server.erl"},{line,1152}]},
{yaws_server,acceptor0,2,
[{file,"yaws_server.erl"},{line,1013}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}
Some version info:
Yaws 1.94
Debian GNU/Linux 7.2 (wheezy)
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Any ideas what this is telling me?
Also, any suggestions for debuggers that are good for beginners is very welcome.
For debugging, I think using Erlang tracing will be helpful. We want to figure out why the yaws_server:skip_data/2 function would be getting a badmatch exception, and specifically why it's getting an empty binary passed to it as that's the only way it could encounter that error. So we need to trace that condition. Try these steps (and don't forget the trailing period on each Erlang shell command):
Run yaws in interactive mode: yaws -i
Once yaws comes up, hit enter to get an Erlang shell prompt.
Create a tracing function for dbg so we get a reasonably formatted backtrace from the trace data: F = fun({trace,_,_,_,Dump},[]) -> io:format("~s~n", [binary_to_list(Dump)]), [] end.
Turn on tracing with this command: dbg:tracer(process, {F, []}).
Trace calls in all processes: dbg:p(all, call).
Now trace the condition of yaws_server:skip_data/2 getting an empty binary as a first argument, and when it does, get a backtrace:
dbg:tpl(yaws_server,skip_data,dbg:fun2ms(fun([<<>>, _]) -> message(process_dump()) end)).
With this in place, start hitting your .yaws page until you provoke the condition, at which point a backtrace will be displayed in your Erlang shell. If you get that backtrace, please copy it into a gist or pastebin and post a link to it as a follow-up here.
If I am correct the output of the out function is supposed to be a list. I didn't check your whole code but the following should work:
<erl>
out(Arg) ->
[{ehtml,
{table, [{width, "100%"}],
{tr,[],
[{td, [{width, "50%"}], "hello world!"},
{td, [{width, "50%"}], "hi again."}]
}
}
}].
</erl>

Riak eating 100% CPU on OSX install

This question is related to:
Riak node not working, but using 100% cpu
but since the poster seems to have left I'm posting my case here.
Last night I installed erlang(R15B01) from source, using the config options from the Riak website:
http://docs.basho.com/riak/1.2.1/tutorials/installation/Installing-Erlang/#Installing-on-Mac-OS-X
and Riak(1.4.1) on my 2013 MacBook Pro (2.8GHz i7, 16GB ram, OSX 10.8.3). I did not change the ulimit, as I assumed it would be fine for a vanilla run.
Installation went fine; warnings but no errors, and I was able to run the toy examples no problem.
However the empty instance quickly ate through all 4 cores and my machine started whining and overheating.
Looking in the logs I see the following error repeated a jillion times:
2013-10-11 09:04:04.266 [error] CRASH REPORT ¥
Process with 0 neighbours exited with reason: ¥
call to undefined function eleveldb:o
also tons of crash reports:
2013-10-11 09:14:47 =CRASH REPORT====
crasher:
initial call: riak_kv_index_hashtree:init/1
pid:
registered_name: []
exception exit: {{undef,[{eleveldb,open,
["./data/anti_entropy/479555224749202520035584085735030365824602865664",
[{create_if_missing,true},{max_open_files,20},{write_buffer_size,12886952}]],[]},
{hashtree,new_segment_store,2,[{file,"src/hashtree.erl"},{line,499}]},{hashtree,new,2,
[{file,"src/hashtree.erl"},{line,215}]},{riak_kv_index_hashtree,do_new_tree,2,
[{file,"src/riak_kv_index_hashtree.erl"},{line,421}]},{lists,foldl,3,[{file,"lists.erl"},
{line,1197}]},{riak_kv_index_hashtree,init_trees,2,[{file,"src/riak_kv_index_hashtree.erl"},
{line,366}]},{riak_kv_index_hashtree,init,1,[{file,"src/riak_kv_index_hashtree.erl"},
{line,226}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]}]},
[{gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]},{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}
ancestors: [,riak_core_vnode_sup,riak_core_sup,]
messages: []
links: []
dictionary: []
trap_exit: false
status: running
heap_size: 987
stack_size: 24
reductions: 492
neighbours:
erlang.log says
=====
===== LOGGING STARTED Fri Oct 11 09:04:01 CEST 2013
=====
Node 'riak#127.0.0.1' not responding to pings.
config is OK
!!!!
!!!! WARNING: ulimit -n is 2560; 4096 is the recommended minimum.
!!!!
Exec: /tmp/riak-1.4.1/rel/riak/bin/../erts-5.9.1/bin/erlexec
-boot /tmp/riak-1.4.1/rel/riak/bin/../releases/1.4.1/riak
-config /tmp/riak-1.4.1/rel/riak/bin/../etc/app.config
-pa /tmp/riak-1.4.1/rel/riak/bin/../lib/basho-patches
-args_file /tmp/riak-1.4.1/rel/riak/bin/../etc/vm.args -- console
Root: /tmp/riak-1.4.1/rel/riak/bin/..
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:8:8] [async-threads:64]
[kernel-poll:true]
Eshell V5.9.1 (abort with ^G)
(riak#127.0.0.1)1>
After less than 10m there are already 144MB of logging files with variations of the above.
I had the same problem by building riak 1.4.6 from source.
I changed in the file etc/app.config the line to
{anti_entropy, {off, []}},
Leveldb is used by AAE. See the config parameter anti_entropy_leveldb_opts.
Use process of elimination:
It's hard to say without more information. Is the 200% being used by
beam.smp? Do you see anything in console.log, error.log or crash.log
that would indicate something odd is happening? Are there clients
communicating with the cluster at the time? If so what client/protocol are
they using and what types of operations are being performed (e.g.
get/put/map reduce/etc)?
References
Riak consuming too much CPU
Interesting sawtooth increasing CPU usage on lightly-used Riak
Inspecting a Node
Riak Performance Tuning
Open Files Limit
Configuration Files

"init terminating in do_boot" error message, when starting Yaws on Windows

I would like to develop a web application in Erlang, so I installed Yaws 1.92 on Windows 7.
But when I try to start Yaws with both yaws and yaws -i I get this error message:
C:\Users\Jonas>yaws
{"init terminating in do_boot",{undef,[{yaws,start,[]},{init,start_it,1},{init,s
tart_em,1}]}}
Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
C:\Users\Jonas>
Is there anything I'm missing? How can I solve this?
With the help from Steve's suggestion, I realised that my Erlang runtime was too old. I upgraded from R14B to R15B. Now Yaws starts, but it still prints some erros on startup:
C:\Users\Jonas>yaws
Eshell V5.9 (abort with ^G)
1>
=INFO REPORT==== 2-Feb-2012::16:22:13 ===
Yaws: Using config file C:\Program Files (x86)\Yaws-1.92\yaws.conf
1>
=ERROR REPORT==== 2-Feb-2012::16:22:13 ===
'auth_log' global variable is deprecated and ignored. it is now a per-server var
iable1>
=INFO REPORT==== 2-Feb-2012::16:22:13 ===
Reading .yaws_auth c:/Program Files (x86)/Yaws-1.92/www/authtest/auth_in_dot_yaw
s_auth/abc/.yaws_auth
1>
=ERROR REPORT==== 2-Feb-2012::16:22:13 ===
Cannot open "c:/Program Files (x86)/Yaws-1.92/logs/localhost.8080.auth"1>
=ERROR REPORT==== 2-Feb-2012::16:22:13 ===
Cannot open "c:/Program Files (x86)/Yaws-1.92/logs/localhost.8080.access"1>
=INFO REPORT==== 2-Feb-2012::16:22:14 ===
Ctlfile : c:/Users/Jonas/AppData/Local/Temp/yaws/default/CTL
1>
=INFO REPORT==== 2-Feb-2012::16:22:14 ===
Yaws: Listening to 0.0.0.0:8080 for <1> virtual servers:
- http://localhost:8080 under c:/Program Files (x86)/Yaws-1.92/www
1>
Any suggestion on why I get so many errors? and how to solve them?
The undef there is saying that the function yaws:start/0 isn't found. Seems like it may be a problem with the load path.
Try starting yaws like this:
yaws -i -erlarg "-boot start_sasl"
Hopefully that will give you more verbose output to help you track down the problem.

Resources