Reloading code upon save?

Skip to first unread message

William Merfalen

May 10, 2017, 1:42:45 AM5/10/17
to MochiWeb
I've added this to my rebar config:

My code is being run within the mochiweb src that is created by the default Makefile. 

I'm calling applcation:start(sync), and then subsequently calling sync:go(), to trigger the "live reload" functionality. 

Does this module not work well with mochiweb? I have valid erlang code that runs fine if I kill the script and recompile (make). 

This is the error I get in the crash report:

exception error: bad function #Fun<telegram_web.0.121416379>
in function  mochiweb_http:call_body/2 (src/mochiweb_http.erl, line 142)
in call from mochiweb_http:headers/6 (src/mochiweb_http.erl, line 122)

The code in mochiweb_http.erl (line 122):
117 headers(Socket, Opts, Request, Headers, Body, HeaderCount) ->
118     ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{active, once}])),
119     receive
120         {Protocol, _, http_eoh} when Protocol == http orelse Protocol == ssl ->
121             Req = new_request(Socket, Opts, Request, Headers),
122             call_body(Body, Req),

It looks like the Body parameter to the headers() function is not valid. 

Bob Ippolito

May 10, 2017, 1:53:20 AM5/10/17
Hard to be certain without more context about what your mochiweb server looks like, but my guess is that you're using an anonymous fun somewhere that causes your processes to die when they don't need to (Erlang will kill processes with anonymous funs that depend on module versions that are getting purged).

If you're using the mochiweb template you could try changing the definition of the body argument from an anonymous fun to an {M, F, A} tuple.


    Loop = fun (Req) ->
        ?MODULE:loop(Req, DocRoot)


    Loop = {?MODULE, loop, [DocRoot]},

You received this message because you are subscribed to the Google Groups "MochiWeb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

William Merfalen

May 10, 2017, 8:22:37 PM5/10/17
to MochiWeb
So I didn't necessarily fix the specific problem with that github library... I did, however, find out that mochiweb comes with a file called reloader.erl. I looked at the code there and I implemented that into my erl files. At first, I thought the reloader would recompile everything for you, but it looks like I have to recompile the erl file myself then call the reloader. I set up a nice little GET request path to handle reloading of the code. I know that's rather dangerous, but this is just a development box and I'm not doing anything serious with it. 

To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
0 new messages