commit | d7059285090850badc20a48e01383e1daa676363 | [log] [tgz] |
---|---|---|
author | Googler <leba@google.com> | Wed Jun 05 07:51:19 2024 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Jun 05 07:52:55 2024 -0700 |
tree | 10f9244779c93ce0086def6cf17b05bbb76fc1f5 | |
parent | c53bbda96f3b9ff97ace3c536fadc547cced0bc6 [diff] |
Fix a potential infinite loop in the case of an interruption. **The Issue** Some external users reported the following sequence: 1. Build starts 2. Build interrupted very early on 3. Another build is started. The command line says "A previous command is running", while the server is stuck. What happened under the hood: The issue could be reproduced very reliably by placing a breakpoint here[1] and interrupt the build. Bazel is in the middle of the recursive `IncrementalPackageRoots.registerAndPlantMissingSymlinks` method when it received the interruption. One important detail: we only add a NestedSet to the `donePackagesRef` set when the _method_ is done successfully. When there's an interruption, we always bail early and never actually reach this line where the NestedSet is added to the set[2]. Without deduplication, this could lead to what feels like an finite loop if the packages are structured like so: ``` [[A], [B, [A]]] ``` In this case, NestedSet `[A]` represents a common child of many NestedSets and would be repeated again and again. We've indeed observed this in a real build, making it unable to finish within any reasonable timeframe. **The Solution** It was overly restrictive to only commit a NestedSet into the de-dup set _after_ all of its symlinks have been planted. It only makes sense if we're planting the symlinks for multiple top-level targets at the same time and want to avoid the situation where a top-level target is allowed to enter execution without all of its symlinks planted. We're already avoiding this situation by design by planting the symlinks for 1 single top-level target at a time. To avoid the near-infinite loop caused by a repeated NestedSet, we add each NestedSet to the de-duplication set the very first time it's seen. **Changes in this CL** - [Bug-fixing] Add a NestedSet to the de-duplication set the very first time it's seen. - [Code simplicity] 1 single blocking `Future.get()` instead of 1 for each recursive layer. Fixes https://github.com/bazelbuild/bazel/issues/22586. --- [1] https://github.com/bazelbuild/bazel/blob/193b114287b3e20850a4b106b889771dfa63a601/src/main/java/com/google/devtools/build/lib/skyframe/IncrementalPackageRoots.java#L253 [2] https://github.com/bazelbuild/bazel/blob/193b114287b3e20850a4b106b889771dfa63a601/src/main/java/com/google/devtools/build/lib/skyframe/IncrementalPackageRoots.java#L256 PiperOrigin-RevId: 640524271 Change-Id: I63c39d7c8f27abaf9229396af1424e775cf5f85f
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.
See CONTRIBUTING.md