Skip to content

Cache directory should account for architecture #36

Open
@sirreal

Description

@sirreal

The compile cache may cause Node to crash if it was generated from a Node build where os.arch() does not match.

I experienced that recently with Node 16 on an Apple M1 machine. I was debugging an issue with yarn and eventually tracked the issue to v8-compile-cache.
yarn had been used with a non-native Node build (os.arch() reported x86), then when a native M1 build of the same node version was installed (os.arch() reported arm64) Node would crash when invoking yarn.

We determined that a compile cache had been generated, but because the compile cache matched independent of the architecture it was incompatible when used across Node binaries —both valid and running on the same machine without issue— and would cause Node to crash.

We were able to resolve the issue by:

  • Invoking yarn with the environment variable as follows: DISABLE_V8_COMPILE_CACHE=1 yarn
  • Finding and removing the generated temporary directories that look like v8-compile-cache*

I believe an appropriate solution would be to add os.arch() to the cache directories around here:

const version = typeof process.versions.v8 === 'string'
? process.versions.v8
: typeof process.versions.chakracore === 'string'
? 'chakracore-' + process.versions.chakracore
: 'node-' + process.version;
const cacheDir = path.join(os.tmpdir(), dirname, version);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions