microsoft/azure-pipelines-vscode

Race condition when accessing azureAccountApi.sessions[0]

stijnherreman opened this issue · 3 comments

There is a race condition in this line:

const token = await azureAccountApi.sessions[0].credentials2.getToken();

Usually the sessions collection is still empty. With some luck I managed to avoid the race condition one time, while stepping through the code. But the only way to reliably avoid the race condition is introducing a delay right before that line, for example with:

        try {
            const gitExtension = await getGitExtensionApi();
            const repo = gitExtension.getRepository(vscode.workspace.workspaceFolders[0].uri);
            await repo.status();
            await repo.status();
            await repo.status();
        } catch (error) {
            return undefined;
        }

Note: I hit a new error when the above part succeeds, but I haven't found the cause yet:

Unable to load schema from 'vscode-userdata:/c%3A/Users/stijn.herreman/AppData/Roaming/Code/User/globalStorage/ms-azure-devops.azure-pipelines/REDACTED-schema.json': Error: Request custom/schema/content failed unexpectedly without providing any details.

Thanks for reporting, @stijnherreman. I also noticed this while testing #481. In my case, I always had at least one session (MSA), but sometimes the second one (AAD) wouldn't load in time.
At any rate, while #481 doesn't fix the race condition, it should make it fail more gracefully since we now loop over it, rather than blindly accessing the first element.

I suspect either I'm not using the Azure Account API correctly, or they're lacking a feature to let us know when all sessions have been loaded. Will try to look into this more closely and figure out which one it is :).

I also noticed this problem. In my case, I had the azure ml studio extension installed. I removed the extension and signed out of the connected azure account. This has temporarily fixed it for me.

Good news - I've figured out why this is happening and how to fix it. I have a few other changes I want to get out in the works, but this will be fixed in the next release.