1

Update: I posted this code here, after I added all (to 99%) possibilities one by one, and it still gave me a 120sec timeout...buffled.


So, ok, I figured it takes exactly 120sec (ok, 122sec) on my Windows 7 machine, until the FIN handshake is started. I want to do it immediately. HTTP RFC793 says

FIN: No more data from sender

Looks to me I do not send any data anymore. I tried all this bloated code, still a Hello World server...

var http = require('http')
var server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'})
    res.write('HELLO WORLD!\n')
    res.end()
    res.setTimeout(0)
    req.abort()     // 1) TypeError: Object #<IncomingMessage> has no method 'abort'

    req.on('socket', function (socket) {
        socket.setTimeout(0)  
        socket.on('timeout', function() {
            req.abort()
        })
    })
})
server.timeout = 0
server.setTimeout(0)
server.listen(1337, '192.168.0.101')
  1. So how to do 1) ? (Actually sends a RST like this...)
  2. And how to do the whole thing HTTP conform?
    Of course in the end I will be lucky to use nodejs as in websocket stuff and all this, but if conversion on my website means a thing of two minutes, and I have a million concurrent users (huh?), sending a FIN immediately could mean I have two million concurrent users (do the math). ;) Ok, to be on the sure side: Sending a FIN means the socket is closed?

  3. Ah, eah, ok, since you are on, how do I console.log(res) or console.log(req)? It gives me [object Object]. (Update: I tried console.log(res.toSource()), gives me a TypeError?
    Edit: Found the answer here.

Community
  • 1
  • 1
loveNoHate
  • 1,549
  • 13
  • 21

1 Answers1

2

If you want to close the connection, send a connection: close header. If you do this, then it will not leave the connection open for reuse.

isaacs
  • 16,656
  • 6
  • 41
  • 31
  • Thank you sir! So the default time of 120secs is not changeable, when I look at my trials? – loveNoHate Feb 22 '14 at 20:47
  • setTimeout(0) removes the timeout entirely. setTimeout(1) would make it 1ms. – isaacs Feb 22 '14 at 22:51
  • Hmm, I still had 2 minutes timeout with all that `0`s. :/ Did not try out anymore on the weekend , was into parallax scrolling haha. Which `setTimeout` do you exactly mean? – loveNoHate Feb 24 '14 at 11:13
  • Keep in mind, this may not be what you want. If this is running live handling multiple connections from the same host the keep-alive will help performance since http requests won't require a new socket to be established. – jeremy Feb 24 '14 at 19:02
  • Hey @jeremy. Just saw your comment now. Yeah, I wanted to be prepared for the task to finish off certain connections ( like a doorguard ;). In the end I found that: `res.end()` does the job alone ( and sends the header ). – loveNoHate Sep 11 '14 at 17:32