Ah yes, you are right. The problem seems to be the connection is closed while the http-parser keeps on reading. I think libuv can improve the error message (rather than assertion error). Assertion error is like something FATAL is violated, I thought it was a bug.
So, this brings the next question: when should we close the connection? https://gist.github.com/1249783 Line 63 closes the connection while the http-parser having a parse error. This will cause the libuv assertion to trigger since the http-parser is still reading. The http-parser docs says you can stop the parser by returning 1 (except on_header_complete). But, the parse error happened during on_read() which returns void. So we cannot tell the http-parser to stop parsing? (while in on_read function) Another way to work around is to never close the connection until the very end. But this is going to be wasting a bit more resources. One other concern is that if the Content-Length of the POST request is bigger than the actual length of the body, then the server will keep on waiting the last bytes. Is there a timeout mechanism in libuv to force close the connection during parsing? 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
