On Mon, Aug 6, 2012 at 8:05 PM, Felix Halim <[email protected]> wrote: > On Tue, Aug 7, 2012 at 1:28 AM, Felix Halim <[email protected]> wrote: >> I am using (the updated) Ryan Dahl's simple webserver: >> >> https://gist.github.com/1249783 >> >> I modify the webserver.c so that instead of responding with a simple >> "hello world", it send a large response about 500KB. >> >> Then these steps below will cause it to silently crash (it just quits >> with error code $? = 141): >> 1. Type http://localhost:8000/hi to your Chrome browser omnibar. >> 2. Press enter then press escape immediately. This will cause >> premature connection termination in the middle of receiving the >> response (it will take several second to receive the whole response). >> >> However, if I do this in node.js, it's fine. So, I guess this is not a >> bug in libuv. >> >> So, my question are: what causes the crash? and how to send large >> response in libuv correctly so that even when the client terminates >> the connection early, it doesn't silently crash? >> >> Here are my modification to the after_write(), and >> on_headers_complete() to give large dynamic response: >> >> >> void after_write(uv_write_t* req, int status) { >> CHECK(status, "write"); >> free(req->data); >> uv_close((uv_handle_t*)req->handle, on_close); >> } >> >> int on_headers_complete(http_parser* parser) { >> client_t* client = (client_t*) parser->data; >> >> LOGF("[ %5d ] http message parsed", client->request_num); >> >> int len = 0, i, j, sz = 50 * 50000; >> char *s = malloc(sizeof(char) * sz); >> for (i=0; i<50000; i++){ >> int c = sprintf(s+len, "hello%d", i); >> len += c; >> assert(len + 1000 < sz); >> } >> client->write_req.data = s; >> resbuf.base = s; >> resbuf.len = len; >> >> uv_write( >> &client->write_req, >> (uv_stream_t*)&client->handle, >> &resbuf, >> 1, >> after_write); >> >> return 1; >> } > > > I sent the above issue to nodejs-dev groups and it doesn't show up in > the googlegroups: > > https://groups.google.com/forum/?fromgroups#!forum/nodejs-dev > > So, I reposted it again here instead (is nodejs-dev a closed group?).
No, but it's moderated and meant for node.js core development. I've canned your post, seeing that you posted here as well. > Additional finding: > > Apparently if I send a response with at most 49188 bytes, it is working fine. > The silent crash is only for responses larger than that. > > Should I use multiple uv_write for large response? No, libuv (and node.js) handles that fine. Chances are high that the bug is in your application. -- 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
