Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fails with run_once is not defined #2

Open
dpovey opened this issue May 1, 2017 · 0 comments
Open

Test fails with run_once is not defined #2

dpovey opened this issue May 1, 2017 · 0 comments

Comments

@dpovey
Copy link

dpovey commented May 1, 2017

I have a test that has 4 different cases. The 4th (and periodically the 3rd) fails with the following error:

Uncaught ReferenceError: run_once is not defined
      at Request._callback (node_modules/auth0-rules-testharness/index.js:69:20)
      at Request.self.callback (node_modules/request/request.js:188:22)
      at Request.<anonymous> (node_modules/request/request.js:1171:10)
      at IncomingMessage.<anonymous> (node_modules/request/request.js:1091:12)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)

This looks like the webtask request is failing with a 429. In this scenario its supposed to set a timer and retry. However the callback "run_once" is not defined.

I fixed this locally, by something like:

if (res.statusCode === 429) {
  var backoff = (+res.headers['retry-after'] || 5) * 1000;
  backoff += Math.floor(Math.random() * backoff);
  winston.debug('scheduling retry of auth0-sandbox request', {
      backoff: backoff
  });
  var run_once = function() {
    request(options, function (err, res, body) {
      if (err) {
        if (typeof err === 'object' && (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT')) {
          return callback(new Error(params.timeout));
        }
        return callback(err);
      }
      process_result(res, body)
    })
  }
  setTimeout(run_once, backoff);
  return;
}

process_result(res, body)

function process_result(res, body) {
    // Previous process flow from here...
    if (res.statusCode !== 200 && res.statusCode !== 500) {

    var errorMessage = 'Invalid response code from the auth0-sandbox: HTTP ' + res.statusCode + '.';
    var parsedBody = toJSON(body);
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant