Skip to content

Commit dc72f30

Browse files
devversiondylhunn
authored andcommitted
fix(bazel): ng module compilation workers are subject to linker race-conditions (#45393)
The Bazel NodeJS rules provide two ways of accessing node modules: * A linker which creates a `node_modules` directory in the execroot/or in the runfiles. * A patched module resolution where no node modules directory necessarily needs to exist. The first is the default in `rules_nodejs` and the second is technically the most idiomatic resolution mechanism in Bazel (as it matches with a runfile resolution library). The linker is prone to race conditions in persistent workers, or non-sandbox environments (like windows). This is because the linker for all workers will operate on a shared `execroot` directory and the same `node_modules` directory is modified all the time / potentially conflicting with other linker processes from other concurrently-running workers. We rely on the patched module resolution anyway, but just need to disable the unused linker to avoid issues like the following: ``` ---8<---8<--- Start of log, file at /private/var/tmp/_bazel_splaktar/280f06d55552a0d01f89f0955b5acd78/bazel-workers/worker-8-TypeScriptCompile.log ---8<---8<--- [link_node_modules.js] An error has been reported: [Error: ENOENT: no such file or directory, unlink 'node_modules'] { errno: -2, code: 'ENOENT', syscall: 'unlink', path: 'node_modules' } Error: ENOENT: no such file or directory, unlink 'node_modules' ---8<---8<--- End of log ---8<---8<--- INFO: Elapsed time: 12.796s, Critical Path: 5.39s INFO: 645 processes: 477 internal, 12 darwin-sandbox, 156 worker. ``` PR Close #45393
1 parent c9d566c commit dc72f30

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/bazel/src/ngc-wrapped/BUILD.bazel

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ nodejs_binary(
3434
"@npm//tslib",
3535
],
3636
entry_point = ":index.ts",
37-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
38-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
39-
templated_args = ["--bazel_patch_module_resolver"],
37+
# Disables the Bazel node modules linker. The node module linker is unreliable for the
38+
# persistent worker executable, as it would rely on the `node_modules/` folder in the
39+
# execroot that can be shared in non-sandbox environments or for persistent workers.
40+
# https://docs.bazel.build/versions/main/command-line-reference.html#flag--worker_sandboxing.
41+
templated_args = ["--nobazel_run_linker"],
4042
visibility = ["//visibility:public"],
4143
)
4244

0 commit comments

Comments
 (0)