v8-compile-cache icon indicating copy to clipboard operation
v8-compile-cache copied to clipboard

Cache directory should account for architecture

Open sirreal opened this issue 3 years ago • 0 comments

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:

https://github.com/zertosh/v8-compile-cache/blob/454af0b0c2f35e6afd87aa1878e1749a76eca122/v8-compile-cache.js#L322-L327

sirreal avatar May 10 '21 15:05 sirreal