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

Unstable behaviour due to missing await #228

Closed
robblovell opened this issue Jun 22, 2021 · 0 comments
Closed

Unstable behaviour due to missing await #228

robblovell opened this issue Jun 22, 2021 · 0 comments

Comments

@robblovell
Copy link

robblovell commented Jun 22, 2021

there is a missing await in index.js in the connect:

This:

async function connect(opts) {
  opts = defaults(opts);
  validate(opts);
  if (opts.authtoken) {
    await setAuthtoken(opts);
  }

  processUrl = await getProcess(opts);
  ngrokClient = new NgrokClient(processUrl);
  return connectRetry(opts);
}

async function connectRetry(opts, retryCount = 0) {
  opts.name = String(opts.name || uuid.v4());
  try {
    const response = await ngrokClient.startTunnel(opts);
    return response.public_url;
  } catch (err) {
    if (!isRetriable(err) || retryCount >= 100) {
      throw err;
    }
    await new Promise((resolve) => setTimeout(resolve, 200));
    return connectRetry(opts, ++retryCount);
  }
}

Should be:

async function connect(opts) {
...
  ngrokClient = new NgrokClient(processUrl);
  return await connectRetry(opts);
}
async function connectRetry(opts, retryCount = 0) {
...
    return await connectRetry(opts, ++retryCount);
  }
}

What I have found is that sometimes it works, but if you are connecting and disconnecting a lot, it becomes undependable as I think there is a race condition without the await.

robblovell added a commit to robblovell/ngrok that referenced this issue Jun 22, 2021
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