Reloading code upon save?

19 views
Skip to first unread message

William Merfalen

unread,
May 10, 2017, 1:42:45 AM5/10/17
to MochiWeb
I've added this to my rebar config: https://github.com/rustyio/sync

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 start-dev.sh 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

unread,
May 10, 2017, 1:53:20 AM5/10/17
to moch...@googlegroups.com
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.

Before:

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

After:

    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 mochiweb+unsubscribe@googlegroups.com.
To post to this group, send email to moch...@googlegroups.com.
Visit this group at https://groups.google.com/group/mochiweb.
For more options, visit https://groups.google.com/d/optout.

William Merfalen

unread,
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 mochiweb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages