Hi,
i've been running a node server application which crashes probably once a 
week due to an uncaught "Can't render headers ..." exception.   The 
skeleton of the code is like:

=================================
var
  httpProxy   = require('http-proxy'),
  spdy        = require('spdy'),
  ...

spdy.createServer
(
  options,
  function(req,res)
  {
    if (...) 
    {
      ...  
      var proxy = new httpProxy.HttpProxy({target: {host: ..., port: 
...}});   //  <1>

      proxy.on
      (
        'proxyError',
         function(err,req,res)
         {
           res.writeHead(500, {'Content-Type': 'text/plain'});
           res.end('Something went wrong and we are reporting a custom 
error message.');
           util.log('!!!!!  ProxyError received');
         }
      );

      proxy.proxyRequest(req,res);    //  <2>
      ...
    }
  }
)
==========================================


In the log file, i can see the message "!!!!!  ProxyError received" being 
printed.

One possible cause of this problem may be related to DNS resolution, HTTP 
proxy, or firewall.   The crash happened at either <1> or <2> even though i 
don't know for sure which.  What is the proper way to guard against such 
server crash in this particular case?   i don't think wrap <1> and/or <2> 
in a try-catch block works due to the asynchronous nature of <1> & <2>.

The stack trace looks like:

     http.js:715
     throw new Error('Can\'t render headers after they are sent to the 
client.'
     ^
     Error: Can't render headers after they are sent to the client.
     at ServerResponse.OutgoingMessage._renderHeaders (http.js:715:11)
     at ServerResponse.writeHead (http.js:1059:20)
     at Socket.proxyError 
(/opt/share/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:193:9)
     at Socket.g (events.js:192:14)
     at Socket.EventEmitter.emit (events.js:126:20)
     at Socket.connect.require.lookup.addressType (net.js:699:16)
     at process.startup.processNextTick.process._tickCallback 
(node.js:245:9)

The node.js version in use is 0.8.22 and the OS distro is RHEL 6.2 but i 
don't think the versions are to be blamed.  

Thanks.

-- 
-- 
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

--- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to