[erlang-questions] cowboy websocket crash, need help

Graham Hay grahamrhay@REDACTED
Fri Jan 16 11:52:19 CET 2015


Hi,

Have you run the parse transform, and started the lager app? Also, is there
a reason you're implementing both the cowboy_http_handler &
cowboy_websocket_handler
behaviours? (That's not the problem, just curious).

Graham


On 16 January 2015 at 05:17, Akash Chowdhury <achowdhury918@REDACTED>
wrote:

> All,
> I am trying to establish an websocket connection using cowboy. I am using
> the base example given in cowboy websocket github. I am getting following
> crash:
>
> 2015-01-15 20:40:01.777 [error] emulator Error in process <0.185.0> on
> node 'erws@REDACTED' with exit value: {[{re
>
> ason,undef},{mfa,{erws_handler,terminate,3}},{stacktrace,[{lager,debug,["terminate"],[]},{erws_handler,terminate,3,[{fi
>
> le,"erws_handler.erl"},{line,48}]},{cowboy_handler,terminate,4,[{file,"cowboy_handler.erl"},{line,69}]},...
>
>
> 2015-01-15 20:40:01.781 [error] <0.81.0> Ranch listener http had
> connection process started with cowboy_protocol:start_
> link/4 at <0.185.0> exit with reason:
> {[{reason,undef},{mfa,{erws_handler,terminate,3}},{stacktrace,[{lager,debug,["ter
>
> minate"],[]},{erws_handler,terminate,3,[{file,"erws_handler.erl"},{line,48}]},{cowboy_handler,terminate,4,[{file,"cowbo
>
> y_handler.erl"},{line,69}]},{cowboy_handler,execute,2,[{file,"cowboy_handler.erl"},{line,54}]},{cowboy_protocol,execute
>
> ,4,[{file,"cowboy_protocol.erl"},{line,467}]}]},{req,[{socket,#Port<0.2498>},{transport,ranch_tcp},{connection,keepaliv
>
> e},{pid,<0.185.0>},{method,<<"GET">>},{version,'HTTP/1.1'},{peer,{{10,69,209,221},49793}},{host,<<"sas755dev.hss.vzwcor
> p.com
> ">>},{host_info,undefined},{port,10100},{path,<<"/websocket">>},{path_info,undefined},{qs,<<>>},{bindings,[]},{hea
> ders,[{<<"host">>,<<"sas755dev.hss.xxxxxx.com:10100">>},{<<"user-agent">>,<<"Mozilla/5.0
> (Windows NT 6.1; rv:34.0) Gec
> ko/20100101
> Firefox/34.0">>},{<<"accept">>,<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},{<<"a
> ccept-language">>,<<"en-US,en;q=0.5">>},{<<"accept-encoding">>,<<"gzip,
> deflate">>},{<<"sec-websocket-version">>,<<"13"
>
> >>},{<<"origin">>,<<"null">>},{<<"sec-websocket-key">>,<<"Uj2HLRfte83Kyu9r9qEesQ==">>},{<<"connection">>,<<"keep-alive,
>
>  Upgrade">>},{<<"pragma">>,<<"no-cache">>},{<<"cache-control">>,<<"no-cache">>},{<<"upgrade">>,<<"websocket">>}]},{meta
>
> ,[]},{body_state,waiting},{buffer,<<>>},{multipart,undefined},{resp_compress,false},{resp_state,waiting},{resp_headers,
>
> []},{resp_body,<<>>},{onresponse,undefined}]},{state,[]},{terminate_reason,{crash,error,undef}}],[{cowboy_handler,execu
>
> te,2,[{file,"cowboy_handler.erl"},{line,59}]},{cowboy_protocol,execute,4,[{file,"cowboy_protocol.erl"},{line,467}]}]}
>
> Here is my erws_handler.erl  file which is almost like example file
> provided in cowboy websocket github
>
> -module(erws_handler).
> -behaviour(cowboy_http_handler).
> -behaviour(cowboy_websocket_handler).
> -export([init/3, handle/2, terminate/3]).
> -export([
>     websocket_init/3, websocket_handle/3,
>     websocket_info/3, websocket_terminate/3
> ]).
>
> init({tcp, http}, _Req, _Opts) ->
>   {upgrade, protocol, cowboy_websocket}.
>
>
> handle(Req, State) ->
>     lager:debug("Request not expected: ~p", [Req]),
>     {ok, Req2} = cowboy_http_req:reply(404, [{'Content-Type',
> <<"text/html">>}]),
>     {ok, Req2, State}.
>
>
> websocket_init(_TransportName, Req, _Opts) ->
>     lager:debug("init websocket"),
>     {ok, Req, undefined_state}.
>
> websocket_handle({text, Msg}, Req, State) ->
>     lager:debug("Got Data: ~p", [Msg]),
>     {reply, {text, << "responding to ", Msg/binary >>}, Req, State,
> hibernate };
>
>
> websocket_handle(_Any, Req, State) ->
>     lager:debug("Got Any"),
>     {reply, {text, << "whut?">>}, Req, State, hibernate }.
>
> websocket_info({timeout, _Ref, Msg}, Req, State) ->
>     lager:debug("websocket info_timeout"),
>     {reply, {text, Msg}, Req, State};
>
> websocket_info(_Info, Req, State) ->
>     lager:debug("websocket info"),
>     {ok, Req, State, hibernate}.
>
> websocket_terminate(_Reason, _Req, _State) ->
>     % lager:debug("websocket terminate. reason: ~p",[_Reason]),
>     lager:debug("websocket terminate"),
>     ok.
>
> terminate(_Reason, _Req, _State) ->
>      % lager:debug("terminate. Reason : ~p",[_Reason]),
>      lager:debug("terminate"),
>     ok.
>
> I am trying from a simple html file through Mozilla Firefox :
>
> ws = new WebSocket("ws://sas755dev.hss.xxxxxx.com:10100/websocket");
>
> I need to provide port number with host name. Is that ok? Does cowboy
> support it? Is providing port number causing this issue? If not, then what
> else? Can anyone help me? Any help regarding this will be highly
> appreciated.
> Thanks.
> -
> Akash
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150116/10aacf15/attachment.htm>


More information about the erlang-questions mailing list