@Kevin:

After double checking what actually happened,
the problem was NOT because of the parser keep on reading the body
when the connection already closed.

In fact, it should be OK for http-parser keep going parsing the body (if exists)
since what http-parser is going to read is already in the buffer.
http-parser only reads when you give the actual data and no more.

The actual problem is because uv_close() is called twice:
- one is called after_write, since the http-parser successfully called
on_headers_complete
- second is called because of "parse error" (see line 63),
(http-parser doesn't expect a body so it doesn't parse it, thus parsed
< nread, causing "parse error" and attempt to call uv_close() again).

This is nicely catched by libuv assert().


@Ben:

I agree that asserts to catch programmers bug is very nice.
However, it would be even nicer if there is an explanation for each assert.

Yes we can decipher the meaning of the assert() ourself like the above case:

    src/unix/core.c:131 suggest that UV_CLOSED bit should not be
present in the handle->flags.
    Which means it should not have been closed before (should not be
called twice).

However, it will save our time in deciphering the guts of libuv code
if there is a comment (in the code) right next after the assert(),
explaining what kind of error each assert() is trying to catch.

That would be very helpful for programmers.

Thanks,

Felix Halim


On Thu, Jul 26, 2012 at 11:59 PM, Kevin Swiber <[email protected]> wrote:
> I believe everything is working as designed.  :)  In that example, a
> response is sent to the client after the headers have been parsed.  The
> connection is closed by the time the parser reaches the request body, and
> this is causing an error.  To read the body, you should look at implementing
> an http_parser_settings.on_body callback.
>
> For more info on the parser, check out:
> https://github.com/joyent/http-parser
>
> On Thu, Jul 26, 2012 at 9:24 AM, Felix Halim <[email protected]> wrote:
>>
>> I think this is the updated example for the Ryan Dahl's tutorial on libuv:
>>
>> https://gist.github.com/1249783
>>
>> I tried running that example, then I tried sending a normal HTTP POST
>> request (via a simple web form) to it and it crashes:
>>
>>
>> listening on port 8000
>> [     1 ] new connection
>> [     1 ] http message parsed
>> parse error
>> [     1 ] connection closed
>> Assertion failed: (!(handle->flags & UV_CLOSED)), function
>> uv__finish_close, file src/unix/core.c, line 130.
>> Abort trap: 6
>>
>>
>> The error comes from libuv's core (not http-parser's).
>>
>> So I guess this is a bug in libuv?
>>
>>
>> The web form I used is a simple html:
>>
>> <form method="POST" action="http://127.0.0.1:8000/blabla";>
>>         <input name="hello" value="world">
>>         <input type="submit" value="here">
>> </form>
>>
>> Run it on a browser and click the button.
>>
>>
>>
>> Felix Halim
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
>
>
> --
> Kevin Swiber
> Projects: https://github.com/kevinswiber
> Twitter: @kevinswiber
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to