[erlang-questions] Cowboy Crash with Postman works fine with CURL

maverik a m4ver1k.a@REDACTED
Wed Apr 3 18:14:30 CEST 2019


Thank you Loic and Zsolt that helped, my bad didn't RTFM properly :(  Now
I'm facing a different Issue.

*But something that still baffles me why is this only happening when
calling from POSTMAN and not CURL.* *I'm on a Arch Linux machine with
Sway/Wayland Compositor. *

New error stacktrace after changing return value from *hello_json *handler:

=CRASH REPORT==== 2-Apr-2019::16:20:53.649647 ===
  crasher:
    initial call: cowboy_stream_h:request_process/3
    pid: <0.445.0>
    registered_name: []
    exception error: function_clause
      in function  cowboy_req:reply/4
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_req.erl,
line 763)
      in call from cowboy_rest:respond/3
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
line 1616)
      in call from cowboy_rest:process_content_type/3
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
line 1106)
      in call from cowboy_rest:upgrade/4
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
line 288)
      in call from cowboy_stream_h:execute/3
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl,
line 296)
      in call from cowboy_stream_h:request_process/3
(/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl,
line 274)
    ancestors: [<0.444.0>,<0.407.0>,<0.406.0>,ranch_sup,<0.395.0>]
    message_queue_len: 0
    messages: []
    links: [<0.444.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 1598
    stack_size: 27
    reductions: 782
  neighbours:

=ERROR REPORT==== 2-Apr-2019::16:20:53.651090 ===
Ranch listener my_http_listener, connection process <0.444.0>, stream 1 had
its request process <0.445.0> exit with reason function_clause and
stacktrace
[{cowboy_req,reply,4,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_req.erl"},{line,763}]},{cowboy_rest,respond,3,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,1616}]},{cowboy_rest,process_content_type,3,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,1106}]},{cowboy_rest,upgrade,4,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,288}]},{cowboy_stream_h,execute,3,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl"},{line,296}]},{cowboy_stream_h,request_process,3,[{file,"/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl"},{line,274}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]


On Tue, Apr 2, 2019 at 3:06 PM Loïc Hoguin <essen@REDACTED> wrote:

> Your hello_post function is returning Req instead of {boolean(), Req,
> State}.
>
> On 02/04/2019 17:04, maverik a wrote:
> > Hi Erlangers,
> >
> > I'm learning Cowboy and facing a peculiar issue.
> > *My handler code* is here. <https://pastebin.com/NQsrj1g0>
> >
> > I have a rest endpoint (POST) and accessing it with Postman show a crash
> > report after giving response. But the very same request works find with
> > CURL.
> >
> > _*CURL Request*:_
> > curl -X POST -d '{"name":"M4ver1k"}' -i -H "User-Agent:
> > PostmanRuntime/7.6.1" -H "Cache-Control: no-cache" -H "postman-token:
> > cc241d1b-d2f0-488d-86ec-0a06bbb13234" -H "connection: keep-alive" -H
> > "Accept-Encoding: gzip, deflate" -H "Content-Type: application/json" -H
> > "Accept: application/json" http://localhost:8080/api/
> >
> > _*Crash Report:*_
> > crasher:
> >      initial call: cowboy_stream_h:request_process/3
> >      pid: <0.1023.0>
> >      registered_name: []
> >      exception error: no try clause matching
> >                       #{bindings => #{},body_length => 17,cert =>
> undefined,
> >                         charset => undefined,has_body => true,
> >                         has_read_body => true,has_sent_resp => true,
> >                         headers =>
> >                             #{<<"accept">> => <<"application/json">>,
> >                               <<"accept-encoding">> => <<"gzip,
> deflate">>,
> >                               <<"cache-control">> => <<"no-cache">>,
> >                               <<"connection">> => <<"keep-alive">>,
> >                               <<"content-length">> => <<"17">>,
> >                               <<"content-type">> =>
> <<"application/json">>,
> >                               <<"host">> => <<"localhost:8080">>,
> >                               <<"postman-token">> =>
> >
> > <<"04b305c1-5214-461e-a1c3-8dcd6b80a621">>,
> >                               <<"user-agent">> =>
> > <<"PostmanRuntime/7.6.1">>},
> >                         host => <<"localhost">>,host_info => undefined,
> >                         media_type => {<<"application">>,<<"json">>,[]},
> >                         method => <<"POST">>,path => <<"/api/">>,
> >                         path_info => undefined,
> >                         peer => {{127,0,0,1},59002},
> >                         pid => <0.1022.0>,port => 8080,qs => <<>>,
> >                         ref => my_http_listener,scheme => <<"http">>,
> >                         sock => {{127,0,0,1},8080},
> >                         streamid => 1,version => 'HTTP/1.1'}
> >        in function  cowboy_rest:call/3
> >
> (/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
>
> > line 1576)
> >        in call from cowboy_rest:process_content_type/3
> >
> (/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
>
> > line 1100)
> >        in call from cowboy_rest:upgrade/4
> >
> (/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_rest.erl,
>
> > line 288)
> >        in call from cowboy_stream_h:execute/3
> >
> (/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl,
>
> > line 296)
> >        in call from cowboy_stream_h:request_process/3
> >
> (/m4ver1k/learn/erlang/hello_cowboy/_build/default/lib/cowboy/src/cowboy_stream_h.erl,
>
> > line 274)
> >      ancestors: [<0.1022.0>,<0.407.0>,<0.406.0>,ranch_sup,<0.395.0>]
> >      message_queue_len: 0
> >      messages: []
> >      links: [<0.1022.0>]
> >      dictionary: []
> >      trap_exit: false
> >      status: running
> >      heap_size: 1598
> >      stack_size: 27
> >      reductions: 770
> >    neighbours:
> >
> >
> > I have run out of options to triage this,trying to understand this
> > behavior.
> >
> > Regards
> > Maverick
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
> --
> Loïc Hoguin
> https://ninenines.eu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190403/66ca15d6/attachment.htm>


More information about the erlang-questions mailing list