fisker / make-synchronized

Make synchronized functions.
MIT License
13 stars 0 forks source link

Unexpected error on Windows #17

Open colinrotherham opened 7 months ago

colinrotherham commented 7 months ago

Since @prettier/sync introduced make-synchronized we've seen unexpected errors thrown on Windows

This doesn't happen all the time and re-running build steps will temporarily resolve the issue

Hope this is helpful for others

Log output

Here's stack trace we've seen regularly but see more examples in https://github.com/alphagov/govuk-frontend/pull/4695

D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:187
        throw new Error(
              ^

Error: Unexpected error, most likely caused by syntax error in 'D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\worker.mjs'
    at #createWorker (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:187:15)
    at ThreadsWorker.sendAction (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:163:40)
    at D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:273:26
    at cacheResult (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:226:25)
    at cachePathResult (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:230:52)
    at _Synchronizer.ownKeys (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:270:12)
    at _Synchronizer.createModule (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:321:29)
    at makeModuleSynchronized (D:\a\govuk-frontend\govuk-frontend\node_modules\make-synchronized\index.cjs:359:59)
    at createSynchronizedPrettier (D:\a\govuk-frontend\govuk-frontend\node_modules\@prettier\sync\index.cjs:6:10)
    at Object.<anonymous> (D:\a\govuk-frontend\govuk-frontend\node_modules\@prettier\sync\index.cjs:9:18)

Node.js v20.11.0
fisker commented 7 months ago

Thanks for reporting this, I tried to

  1. clone the repo
  2. upgrade @prettier/sync to v0.5.0 in packages/govuk-frontend-review/
  3. Run yarn jest --color --coverage=false --maxWorkers=2 --selectProjects "Accessibility tests"

But I can't see any error. Did I do something wrong?

fisker commented 7 months ago

After cleaning .cache and run tests on Node.js 20.9.0, still can't get an error.

colinrotherham commented 7 months ago

Thanks @fisker

Looks like your PR + a few re-runs didn't get the error either today

If we take a look at the GitHub Actions runs that failed last week:

The npm package lines in make-synchronized/index.cjs (compiled from threads-worker.js) throw at:

try {
  lock.lock(1e3);
} catch (error) {
  if (error instanceof atomics_wait_timeout_error_default) {
    throw new Error(
      `Unexpected error, most likely caused by syntax error in '${WORKER_FILE}'`
    );
  }
  throw error;
}

Perhaps on GitHub Actions, under some loads, we're seeing the 1000ms timeout is too slow?

Rather than syntax error

fisker commented 7 months ago

Removed that check in #25, you can try @prettier/sync v0.5.1. https://github.com/prettier/prettier-synchronized/releases/tag/v0.5.1