question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: require-atomic-updates misleading error message

See original GitHub issue

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;
  });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, 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 https://github.com/eslint/eslint/issues/11899), and I’m working on that.

0reactions
m90commented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

require-atomic-updates - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
await async - race condition error in ESLint require-atomic ...
In this case, race memoizes value on the stack, await s a tick, then writes back to value . As other code runs...
Read more >
Disallow assignments that can lead to race conditions due to ...
Disallow assignments that can lead to race conditions due to usage of await or yield (require-atomic-updates). When writing asynchronous code, ...
Read more >
Java™ SE Development Kit 8 Update 60 Bug Fixes - Oracle
Bug Fixes ; JDK-8076265, hotspot, gc, Simplify deal_with_reference ; JDK-8077255, hotspot, gc, TracePageSizes output reports wrong page size on Windows with G1.
Read more >
Common Error Messages | Sauce Labs Documentation
The most common causes for this error are either unresponsive JavaScript in your app, or a bug in Selenium/Appium. A less common, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found