Skip to content

global group can deadlock requests if auth is not already cached #754

@hanskr

Description

@hanskr

When running Octokit with auth, and trying to concurrently perform 10+ operations, a deadlock will happen.
The reason: https://github.com/octokit/plugin-throttling.js/blob/main/src/index.ts#L30
10 concurrent in global. If this buffer is filled with 10 requests, and no auth token is present, the auth request will end up as number 11, and never run, again causing the 10 requests in the queue to wait forever.

Example code to reproduce:

const octokit = await (new App({
  appId,
  privateKey,
  Octokit: Octokit.defaults({
    baseUrl,
  }),
})).getInstallationOctokit(installationId);

const artifacts = [
  'test-1',
  'test-2',
  'test-3',
  'test-4',
  'test-5',
  'test-6',
  'test-7',
  'test-8',
  'test-9',
  'test-10'
];

//await fetchLastSuccessfulDeployment('fis', 'ban', 'Finn', 'horizontal');
await Promise.all(
  artifacts.map(async (artifact) => {
    return await await octokit.rest.actions.listWorkflowRuns({
      owner: 'owner',
      repo: 'repo',
      workflow_id: `deploy.${artifact}.yaml`,
    });
  })
);

This will hang forever.

By reducing the array to 9 elements, it works.
By awaiting a single request before looping, it works (remove the comment before the loop, this will get a token and cache it).
By changing maxConcurrent to 11, it works.

I think it would be a good idea to let auth requests have its own queue, and not end up in the global one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documentedreleased

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions