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

Bug: require-atomic-updates misleading error message #15076

Closed
1 task done
m90 opened this issue Sep 17, 2021 · 5 comments · Fixed by #15109
Closed
1 task done

Bug: require-atomic-updates misleading error message #15076

m90 opened this issue Sep 17, 2021 · 5 comments · Fixed by #15109
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes
Projects

Comments

@m90
Copy link

m90 commented Sep 17, 2021

Environment

Node version: v14.15.5
npm version: 7.23.0
Local ESLint version: 7.32.0
Global ESLint version: -
Operating System: Ubuntu 20.04

What parser are you using?

Default (Espree)

What did you do?

Configuration
    // ...
    'require-atomic-updates': 2,
    // ...
'use strict';

const opts = {}; // stubbed for repro
const run = () => Promise.resolve({ exit_code: 0 }); // stubbed for repro

(async () => {
  if (opts._.length) {
    if (opts._[0] === '-') {
      opts.spec = process.stdin;
    } else {
      opts.spec = opts._;
    }
  }
  delete opts._;
  try {
    const { exit_code } = await run(opts);
    process.exitCode = exit_code;
  } catch (e) {
    console.error(e.stack);
    process.exitCode = 1;
  }
})();

Playground version

What did you expect to happen?

I would expect the above code not to raise require-atomic-updates.

What actually happened?

I'm seeing

  17:5  error  Possible race condition: `process.exitCode` might be reassigned based on an outdated value of `process.exitCode`  require-atomic-updates
  20:5  error  Possible race condition: `process.exitCode` might be reassigned based on an outdated value of `process.exitCode`  require-atomic-updates

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

This started happening after adding a simple condition where opts.spec might be assigned to process.stdin.

Before the change code read like this and passed the rule:

'use strict';

const opts = {}; // stubbed for repro
const run = () => Promise.resolve({ exit_code: 0 }); // stubbed for repro

(async () => {
  if (opts._.length) {
    opts.spec = opts._;
  }
  delete opts._;
  try {
    const { exit_code } = await run(opts);
    process.exitCode = exit_code;
  } catch (e) {
    console.error(e.stack);
    process.exitCode = 1;
  }
})();

I have a hard time understanding how the change introduces a possible race condition (maybe I'm wrong though), so I would assume this is a bug. In case it is a bug I would be happy to submit a PR in case someone can point me to a place where I can start.


Edit: unwrapping the async function and using a Promise chain instead does not raise any warnings when including the conditional assignment:

'use strict';

const opts = {}; // stubbed for repro
const run = () => Promise.resolve({ exit_code: 0 }); // stubbed for repro

if (opts._.length) {
  if (opts._[0] === '-') {
    opts.spec = process.stdin;
  } else {
    opts.spec = opts._;
  }
}
delete opts._;

run(opts)
  .catch((err) => {
    console.error(err.stack);
    return { exit_code: 1 };
  })
  .then(({ exit_code }) => {
    process.exitCode = exit_code;
  });
@m90 m90 added bug ESLint is working incorrectly repro:needed labels Sep 17, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Sep 17, 2021
@nzakas
Copy link
Member

nzakas commented Sep 25, 2021

I’m not very familiar with this rule, by based on the rather nonsensical error message it’s producing, I’d guess this is a bug.

@eslint/eslint-tsc thoughts?

@nzakas nzakas moved this from Needs Triage to Feedback Needed in Triage Sep 25, 2021
@btmills
Copy link
Member

btmills commented Sep 25, 2021

This invalid test case added in #11774 looks to be related:

https://github.com/eslint/eslint/blob/07175b8e9532d79e55c499aa27f79f023abda3c3/tests/lib/rules/require-atomic-updates.js#L322L331

It looks like even though different properties on the object are being read and assigned, the rule considers the whole object stale. I can’t tell based on the issue and PR discussion whether that behavior is intentional, however.

@mdjermanovic
Copy link
Member

mdjermanovic commented Sep 27, 2021

I think this is the same as #11899.

Based on the discussion in #11899, I believe this is intended behavior, but the error message is wrong (or at least misleading).

@m90
Copy link
Author

m90 commented Sep 27, 2021

I agree this sounds pretty much like a duplicate of #11899 - feel free to close this if it makes sense for you and thanks for looking into this.

@mdjermanovic
Copy link
Member

mdjermanovic commented Sep 27, 2021

Thanks for the confirmation! I'll mark this as accepted to fix the error message (it doesn't seem it was mentioned in #11899), and I'm working on that.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Sep 27, 2021
@mdjermanovic mdjermanovic self-assigned this Sep 27, 2021
@mdjermanovic mdjermanovic moved this from Feedback Needed to Ready to Implement in Triage Sep 27, 2021
@mdjermanovic mdjermanovic changed the title Bug: require-atomic-updates is raised after unrelated change Bug: require-atomic-updates misleading error message Sep 27, 2021
@mdjermanovic mdjermanovic moved this from Ready to Implement to Pull Request Opened in Triage Sep 27, 2021
Triage automation moved this from Pull Request Opened to Complete Oct 9, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 8, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:yes
Projects
Triage
Complete
Development

Successfully merging a pull request may close this issue.

4 participants