Added res.headersSent if test to res in request.on.socket timeout callback method and req.on error event callback method to prevent error.