aspect-build / rules_js

High-performance Bazel rules for running Node.js tools and building JavaScript projects
https://docs.aspect.build/rules/aspect_rules_js
Apache License 2.0
299 stars 103 forks source link

[Bug]: NpmPackageExtract error with 1.40.1 #1597

Closed danielepolencic closed 4 months ago

danielepolencic commented 5 months ago

What happened?

Since I upgraded to 1.40.1 I can see this error when I build the project:

danielepolencic lms % bazel run //packages/router --action_env=VERSION="1" --sandbox_debug --verbose_failures -- -p 3000 -w learnk8s 
INFO: Invocation ID: 2efabfaf-71e0-4c71-bac7-49a6315e45f4
INFO: Analyzed target //packages/router:router (0 packages loaded, 0 targets configured).
ERROR: /Users/danielepolencic/Sites/learnk8s/lms/BUILD.bazel:9:22: Extracting npm package nopt@1.0.10 failed: (Exit 1): sandbox-exec failed: error executing NpmPackageExtract command 
  (cd /private/var/tmp/_bazel_danielepolencic/85fb369c77069c2b444971b4d8df672f/sandbox/darwin-sandbox/2849/execroot/_main && \
  exec env - \
    TMPDIR=/var/folders/rv/qc4y1xpj31j4n0jwkpmz3jhh0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_danielepolencic/85fb369c77069c2b444971b4d8df672f/sandbox/darwin-sandbox/2849/sandbox.sb /var/tmp/_bazel_danielepolencic/install/58245ff4f4f98ce7a7649fb05b99d8df/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_danielepolencic/85fb369c77069c2b444971b4d8df672f/sandbox/darwin-sandbox/2849/stats.out' external/bsd_tar_darwin_arm64/tar --extract --no-same-owner --no-same-permissions --strip-components 1 --file external/npm__nopt__1.0.10/package.tgz --directory bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/nopt@1.0.10/node_modules/nopt)
gzip: (stdin): trailing garbage ignored
tar: Error opening archive: (null)
Target //packages/router:router failed to build
INFO: Elapsed time: 1.979s, Critical Path: 1.33s
INFO: 31 processes: 10 disk cache hit, 21 internal.

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 7.0.2

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

http_archive(
    name = "aspect_rules_js",
    sha256 = "d7500d59712accca9622bce723b8ea596b92fb9b4ff4a4dbd77ed353b9d29f34",
    strip_prefix = "rules_js-1.40.1",
    url = "https://github.com/aspect-build/rules_js/releases/download/v1.40.1/rules_js-v1.40.1.tar.gz",
)

How to reproduce

No response

Any other information?

Reverting to 1.40.0 fixes the issue.

gregmagolan commented 4 months ago

Hmm. The notable change between 1.40.0 and 1.40.1 is that we bumped bazel-lib to a version that brought in a pre-built tar linked against musl. https://github.com/aspect-build/rules_js/pull/1556. Guessing the breakage came from in there.

cc @alexeagle @dzbarsky

gregmagolan commented 4 months ago

@Aghassi also reported hitting this

Aghassi commented 4 months ago

Just confirming we also had to bump our bazel-lib to 1.42.2 internally for this upgrade so we are on that version which aligns with the suspicion Greg cited

gregmagolan commented 4 months ago

@Aghassi @danielepolencic was the failure on a single npm package, a subset of packages or all packages on your builds?

Aghassi commented 4 months ago

@gregmagolan

image

This is the error we are seeing on our pipeline that is failing

gregmagolan commented 4 months ago

This is the error we are seeing on our pipeline that is failing

Same dep. Great. I'll see if I can repro that on rules_js in that case.

gregmagolan commented 4 months ago

I'm able to repro it in rules_js with this change: https://github.com/aspect-build/rules_js/pull/1657.... but only on darwin. Linux CI is all green.

Aghassi commented 4 months ago

Correct, we only have it on Darwin too

aaliddell commented 4 months ago

I'm getting basically the same thing during NpmPackageExtract only on Windows on 1.40.1:

ERROR: C:/users/user/repos/project/BUILD.bazel:18:22: Extracting npm package yocto-queue@0.1.0 failed: (Exit -1073741515): bsdtar.exe failed: error executing NpmPackageExtract command (from target //:.aspect_rules_js/node_modules/yocto-queue@0.1.0/pkg)
  cd /d C:/users/user/_bazel_user/bcrtdr5p/execroot/_main
external\aspect_bazel_lib~1.42.2~toolchains~bsd_tar_windows_amd64\libarchive\bin\bsdtar.exe --extract --no-same-owner --no-same-permissions --strip-components 1 --file external/aspect_rules_js~1.40.1~npm~js_deps__yocto-queue__0.1.0/package.tgz --directory bazel-out/x64_windows-opt/bin/node_modules/.aspect_rules_js/yocto-queue@0.1.0/node_modules/yocto-queue
# Configuration: 24065dc4cfd16feb0d9c94e85894e0bb03247f8d38981abd6c98c2262748fa0f
# Execution platform: @@local_config_platform//:host

If I run the same commands manually it works fine, which suggests it may be a sandbox thing and if I have to guess it's perhaps because the archive.dll is not being found when run under Bazel, as tar_toolchain makes no reference to it.

dzbarsky commented 4 months ago

@Aghassi great, I have a fix, I'll send out patches and get this percolating through the repos.

@aaliddell Would you mind filing a separate issues for that one? We are not using the hermetically linked bsdtar on Windows, so it would need a separate fix.

gregmagolan commented 4 months ago

Working down the supply chain

gregmagolan commented 4 months ago

Released bazel-lib 1.42.3 and 2.7.1 with the fix.

rules_js minimum bump on 1.x branch: https://github.com/aspect-build/rules_js/pull/1672

gregmagolan commented 4 months ago

Fix released in v1.14.2