[erlang-questions] Any tcp related changes in R15B* that might cause this?

Anthony Molinaro anthonym@REDACTED
Thu Dec 13 01:24:55 CET 2012


Okay, I found it.  Looks like this is the cause

OTP-9389  Honor option packet_size for http packet parsing by both TCP
          socket and erlang:decode_packet. This gives the ability to
          accept HTTP headers larger than the default setting, but also
          avoid DoS attacks by accepting lines only up to
          whatever length you wish to allow. For consistency,
          packet type line also honor option packet_size. (Thanks
          to Steve Vinoski)

With R14B04 when you have a header which is too long, your process
gets a message like

{http,#Port<0.120387186>,{http_error,"X2qutbTBbXg7VHgDDhGrEvDbzuxiyDlI7VFloMyAJKVqY2fTEkMc70UchLPRG8Cjowzmib4KszbCRwA5IBbAd2MbRi5X_tK2nfRtheavXdhQv8XbinzmhCM1E9YCeuFAg_9TfqUS0sWUd52mgjkWGqNe4Z9S0IxFYnFtf5..."}}

in R15B02 you get a message like

{tcp_error,#Port<0.104208233>,emsgsize}

The prior case is handled correctly by mochiweb, the latter is not.

I'm not sure if the commits for OTP-9389 actually caused this change or if
it was some other change.  Also, not sure if it was meant to be a backward
compatible change or not (the comment on the commit
https://github.com/erlang/otp/commit/5984409d1264871cbe61bfec875de53e51713efb
seems to suggest it was supposed to be backward compatible, but maybe this
was a side effect?  It seems like emsgsize is more correct.

-Anthony

On Wed, Dec 12, 2012 at 03:48:03PM -0800, Anthony Molinaro wrote:
> Okay, here's some more information, seems like the real error is
> 
> {tcp_error,#Port<0.98735301>,emsgsize}
> 
> earlier.  So maybe sometime between R14B04 and R15B02 the handling of
> emsgsize changed?
> 
> I think what happens with mochiweb is it has a receive which matches several
> message types, then has a catch all.  The catch all gets the emsgsize error
> and the tcp_closed error is in the mailbox, then the code handling the catch
> all attempts to setopts on the socket and gets the einval error because
> the socket is closed.
> 
> So I'm really curious what might have changed in the tcp driver that might
> have changed this behavior.  I'm trying to figure out how to reproduce so
> I can patch mochiweb to work around this (most likely by just adding a
> clause to the receive).
> 
> -Anthony
> 
> On Wed, Dec 12, 2012 at 10:26:32AM -0800, Anthony Molinaro wrote:
> > Well, yes, I did see the tcp_closed message, my real question is I guess
> > related to your statement
> > 
> > "It may be that R15 is more accurate at reporting here than R14, so the older version just accepts the result blindly and then have the no change, whereas R15 actually reports the correct error."
> > 
> > Can anyone from OTP clarify if any work was done with regards to error
> > messages?  I did not find anything in the release notes which is why
> > I'm wondering.
> > 
> > I suppose I could attempt to git bisect this or something, but I'm not
> > sure how difficult that might be.
> > 
> > Thanks,
> > 
> > -Anthony
> > 
> > On Wed, Dec 12, 2012 at 05:18:57PM +0100, Jesper Louis Andersen wrote:
> > > 
> > > On Dec 6, 2012, at 8:38 PM, Anthony Molinaro <anthonym@REDACTED> wrote:
> > > 
> > > > 2012-12-01 00:01:33 =CRASH REPORT====
> > > >  crasher:
> > > >    initial call: mochiweb_acceptor:init/3
> > > >    pid: <0.2942.3599>
> > > >    registered_name: []
> > > >    exception error: {{badmatch,{error,einval}},[{mochiweb_http,new_request,3,[]},{mochiweb_http,handle_invalid_request,3,[]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}
> > > >    ancestors: [webmachine_mochiweb,web_serve_sup,<0.619.0>]
> > > >    messages: [{tcp_closed,#Port<0.222190389>}]
> > > >    links: [<0.873.0>]
> > > >    dictionary: []
> > > >    trap_exit: false
> > > >    status: running
> > > >    heap_size: 987
> > > >    stack_size: 24
> > > >    reductions: 541
> > > >  neighbours:
> > > 
> > > If you read through the Mochi code, you will see this:
> > > 
> > > https://github.com/mochi/mochiweb/blob/master/src/mochiweb_http.erl#L125
> > > 
> > >     ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
> > > 
> > > So assuming that is true, the problem is a posix() message einval (Invalid Argument), probably because the
> > > socket is long dead and gone. It may be that R15 is more accurate at reporting here than R14, so the older version just accepts the result blindly and then have the no change, whereas R15 actually reports the correct error.
> > > 
> > > A thing supporting my hypothesis is that there is a tcp_closed message in your mailbox :)
> > > 
> > > 
> > > Jesper Louis Andersen
> > >   Erlang Solutions Ltd., Copenhagen
> > > 
> > > 
> > > 
> > 
> > -- 
> > ------------------------------------------------------------------------
> > Anthony Molinaro                           <anthonym@REDACTED>
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> 
> -- 
> ------------------------------------------------------------------------
> Anthony Molinaro                           <anthonym@REDACTED>

-- 
------------------------------------------------------------------------
Anthony Molinaro                           <anthonym@REDACTED>



More information about the erlang-questions mailing list