UPDATED code with 'finish' event
var http=require("http"),
server = null;
server = http.createServer(function (request, response) {
request.on("end", function(){
console.log("server: reqest end " + new Date());
});
response.on('finish', function () {
console.log('server: response finish ' + new Date());
});
response.on('close', function () {
console.log('server: response close ' + new Date() );
});
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
server.on('request', function(sock) {
console.log('server: got request ' + new Date());
});
setTimeout(function(){
console.log('server: calling server.close ' + new Date() );
server.close(function() {
console.log('server: has closed ' + new Date() )
});
}, 10000);
LOG:
> node app/http_server_test.js
server: got request Thu Aug 13 2015 10:45:36 GMT+0530 (IST)
server: response finish Thu Aug 13 2015 10:45:36 GMT+0530 (IST)
server: reqest end Thu Aug 13 2015 10:45:36 GMT+0530 (IST)
server: calling server.close Thu Aug 13 2015 10:45:41 GMT+0530 (IST)
server: has closed Thu Aug 13 2015 10:47:32 GMT+0530 (IST)
On Thursday, August 13, 2015 at 10:43:17 AM UTC+5:30, Kiran Ravuri wrote:
>
> There are no pending requests. As you can see in the log there is only one
> request and server replied to that and i got 'end' event for that.
>
> With out any requests if i give server.close() is working properly. Even
> if it servers one request it is taking long to close. You can just copy
> paste that code in your test environment and send a request to
> localhost:3000 to observe the behaviour.
>
>
>
> On Thursday, August 13, 2015 at 1:38:33 AM UTC+5:30, Maximilian Hill wrote:
>>
>> Maybe the socket is wariting for FIN of some connrctions.
>>
>> Max
>> Am 12.08.2015 21:39 schrieb "Kiran Ravuri" <[email protected]>:
>>
>>> Hi All,
>>>
>>> I am testing cluster in node, and i had a question regarding that which
>>> i posted
>>>
>>> @
>>> http://stackoverflow.com/questions/31934358/nodejs-worker-disconnect-not-working-as-expected
>>>
>>>
>>> This is the followup question to that, cos i found the similar behavior
>>> in this test .
>>>
>>> *SERVER :*
>>>
>>> var http=require("http"),
>>> server = null;
>>>
>>> server =http.createServer(function (request, response) {
>>> request.on("end", function(){
>>> console.log("reqest end " + new Date());
>>> });
>>> request.on("data", function(data) {
>>> console.log("I am here");
>>> console.log(data.toString("utf8"));
>>> });
>>> response.writeHead(200, {'Content-Type': 'text/plain'});
>>> response.end('Hello World\n');
>>> }).listen(3000);
>>>
>>> server.on('request', function(sock) {
>>> console.log('Got Request ' + new Date());
>>> });
>>>
>>> setTimeout(function(){
>>> console.log('SERVER: calling server.close ' + new Date() );
>>> server.close(function() {
>>> console.log('SERVER: has closed ' + new Date() )
>>> });
>>> }, 5000);
>>>
>>> *LOG:*
>>>
>>> > node app/http_server_test.js
>>> Got Request Wed Aug 12 2015 20:09:21 GMT+0530 (IST)
>>> reqest end Wed Aug 12 2015 20:09:21 GMT+0530 (IST)
>>> SERVER: calling server.close Wed Aug 12 2015 20:09:23 GMT+0530 (IST)
>>> SERVER: has closed Wed Aug 12 2015 20:11:17 GMT+0530 (IST)
>>>
>>> My question is why the server is taking that much time( about 2 mins) to
>>> close even though there are no pending requests in the queue??
>>>
>>> Thanks in advance.
>>>
>>> BRs
>>> Kiran
>>>
>>>
>>> --
>>> Job board: http://jobs.nodejs.org/
>>> New group rules:
>>> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
>>> Old group rules:
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/nodejs/f2f4e2e0-0954-485e-a496-c0e9ba285cfa%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/nodejs/f2f4e2e0-0954-485e-a496-c0e9ba285cfa%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/6b772d61-2339-4a0f-96e7-ffbf22447766%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.