Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2621 from 6a68/issue-2603-tighten-wellknown-timeouts
Browse files Browse the repository at this point in the history
Add a timeout when trying to fetch a well-known. Fixes #2603.
  • Loading branch information
seanmonstar committed Oct 23, 2012
2 parents 874a152 + 6993ed4 commit 380f33a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/configuration.js
Expand Up @@ -225,8 +225,9 @@ var conf = module.exports = convict({
process_type: 'string',
email_to_console: 'boolean = false',
declaration_of_support_timeout_ms: {
doc: "The amount of time we wait for a server to respond with a declaration of support, before concluding that they are not a primary. Only relevant when our local proxy is in use, not in production or staging",
format: 'integer = 15000'
doc: "The amount of time we wait for a server to respond with a declaration of support, before concluding that they are not a primary. Needs to be shorter than the dialog's time_until_delay param to avoid xhr-delay UI.",
format: 'integer = 8000',
env: 'DECLARATION_OF_SUPPORT_TIMEOUT_MS'
},
enable_development_menu: {
doc: "Whether or not the development menu can be accessed",
Expand Down
10 changes: 10 additions & 0 deletions lib/primary.js
Expand Up @@ -13,6 +13,7 @@ logger = require('./logging.js').logger,
urlparse = require('urlparse'),
jwcrypto = require("jwcrypto"),
config = require("./configuration.js"),
primaryTimeout = config.get('declaration_of_support_timeout_ms'),
secrets = require("./secrets.js");

// alg
Expand Down Expand Up @@ -201,7 +202,16 @@ var getWellKnown = function (domain, delegates, cb) {
}, handleResponse);
}

// front-end shows xhr delay message after 10 sec; timeout sooner to avoid this
var reqTimeout = setTimeout(function() {
req.abort();
logger.debug('timeout trying to load well-known for ' + domain + ': ' + e.toString());
handleProxyIDP();
}, primaryTimeout);
req.on('response', function() { clearTimeout(reqTimeout) });

req.on('error', function(e) {
if (reqTimeout) { clearTimeout(reqTimeout); }
logger.debug(domain + ' is not a browserid primary: ' + e.toString());
handleProxyIDP();
});
Expand Down

0 comments on commit 380f33a

Please sign in to comment.