On Sun, Nov 18, 2012 at 7:02 PM, Érick Lavoie <erick.lav...@gmail.com> wrote: > Hi, > > I am trying to update the server code while it is running. If my > understanding is correct, I should first close the http server and once the > close operation has been performed, I can create another HttpServer > listening to the same port and host with the new code. > > However, on Node 0.8.14, closing the server inside a request, like in the > following example: > > var http = require('http'); > > server = http.createServer(function (req, res) { > res.writeHead(200, {'Content-Type': 'text/plain'}); > res.end('Hello World\n'); > server.close(); > }); > server.listen(8080, function () { > console.log('Server running at http://localhost:8080/'); > }); > > throws the following exception: > > net.js:1046 > throw new Error('Not running'); > ^ > Error: Not running > at Server.close (net.js:1046:11) > at Server.<anonymous> > (/Users/erick/Documents/UdeM/Recherche/distributed-js/hello.js:6:12) > at Server.EventEmitter.emit (events.js:99:17) > at HTTPParser.parser.onIncoming (http.js:1807:12) > at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] > (http.js:111:23) > at Socket.socket.ondata (http.js:1704:22) > at TCP.onread (net.js:403:27) > > Surprisingly, closing the server in the listening callback does work. Is > there a way to do it while processing a request or is there some policy > preventing it from being done?
I wager you're testing it with a browser. What happens is that you call server.close() twice because your browser makes two requests, one for / and one for /favicon.ico. Make the request with curl and you'll find that the server shuts down gracefully. -- 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 nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en