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

fix: wait to read until file is unlocked #1116

Merged
merged 13 commits into from
Aug 7, 2024
Merged

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Aug 1, 2024

What does this PR do?

Wait to read config files until file is unlocked. This fixes an issue where parallel command executions caused files reads to return empty.

QA

In a linked plugin (with this branch of sfdx-core linked), create a new command that creates an AuthInfo and calls .save()

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages, AuthInfo } from '@salesforce/core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-parallel-auth', 'hello.world');

export default class World extends SfCommand<void> {
  public static readonly summary = messages.getMessage('summary');
  public static readonly description = messages.getMessage('description');
  public static readonly examples = messages.getMessages('examples');

  public static readonly flags = {
    org: Flags.requiredOrg(),
  };

  public async run(): Promise<void> {
    const { flags } = await this.parse(World);

    const username = flags.org.getUsername();
    if (!username) {
      return;
    }

    this.log(`Updating auth info for ${username} (PID: ${process.ppid})`);
    const authInfo = await AuthInfo.create({ username });
    authInfo.update({ username });
    await authInfo.save();
  }
}

In dreamhouse-lwc, create a scratch org then run the command 10 times in parallel:

sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
sf hello world --org my-org & \
wait

NOTE: this repros the issue ~50% of the time

I would consider it successful if you don't see any JSON parsing issues in 10 consecutive attempts

What issues does this PR fix or reference?

@W-16322519@

@mdonnalley mdonnalley requested a review from a team as a code owner August 1, 2024 18:12
Copy link
Contributor

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved. feedback was done via PRs.

QA: wrote a NUT and had Mike re-check the changes using his original local replication.

@mshanemc mshanemc merged commit e4a703f into main Aug 7, 2024
68 checks passed
@mshanemc mshanemc deleted the mdonnalley/wait-until-unlock branch August 7, 2024 20:06
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

Successfully merging this pull request may close these issues.

3 participants