Commit d705928
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 #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: I63c39d7c8f27abaf9229396af1424e775cf5f85f1 parent c53bbda commit d705928
File tree
1 file changed
+30
-24
lines changed- src/main/java/com/google/devtools/build/lib/skyframe
1 file changed
+30
-24
lines changedLines changed: 30 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
210 | 214 | | |
211 | 215 | | |
212 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
| |||
224 | 242 | | |
225 | 243 | | |
226 | 244 | | |
227 | | - | |
228 | | - | |
229 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
230 | 250 | | |
231 | 251 | | |
232 | | - | |
| 252 | + | |
233 | 253 | | |
234 | 254 | | |
235 | 255 | | |
236 | | - | |
237 | 256 | | |
238 | 257 | | |
239 | 258 | | |
| |||
246 | 265 | | |
247 | 266 | | |
248 | 267 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
| 268 | + | |
| 269 | + | |
262 | 270 | | |
263 | | - | |
264 | | - | |
265 | 271 | | |
266 | 272 | | |
267 | 273 | | |
| |||
0 commit comments