Commit e886904
authored
fix(ci_visibility): git multi-process issues (#18156)
## Description
Fixes two sources of spurious git warning logs that customers see when using the pytest plugin under pytest-xdist (or other multi-process) environments.
**Problem 1: shallow lock contention**
Multiple xdist workers each call `git fetch --update-shallow` during startup. They all compete for `.git/shallow.lock`, causing repeated `fatal: Unable to create '.../.git/shallow.lock': File exists` warnings. Fixed by:
- Adding `_call_git_with_lock_retry()` in `git.py`, which retries up to 5 times with exponential back-off + jitter when lock contention is detected.
- Forcing `LC_ALL=C` / `LANG=C` in `_call_git()` so git's error messages are always in English, making the lock-contention regex reliable regardless of the user's locale.
- Short-circuiting `unshallow_repository()` at entry when the repo is already non-shallow (a sibling worker may have finished unshallowing while we were waiting on the lock), and aborting the retry loop early under the same condition.
**Problem 2: merge-base called on a shallow repo**
`git merge-base` was called inside `get_env_tags()`, which runs at plugin startup before any unshallowing. On shallow clones the commits aren't locally available yet, so the call always fails silently. Fixed by:
- Removing the call from `get_env_tags()` and deferring it to the new `SessionManager._update_pr_merge_base()` helper, which is called from `upload_git_data()` after unshallowing has completed.
- Moving the "all commits already in backend" early-return in `upload_git_data()` to run *after* `_update_pr_merge_base()`, so `PULL_REQUEST_BASE_BRANCH_SHA` is always populated even when no pack upload is needed.
- The standalone helper `get_pr_base_commit_sha()` that was the only caller is removed as dead code.
## Testing
New tests added:
- `TestGitLockRetry` — unit tests for `_call_git_with_lock_retry`: success path, non-lock errors skip retry, lock error retries then succeeds, retry exhaustion returns last failure, `unshallow_repository` uses the retry helper, `unshallow_repository` skips the fetch when the repo is already non-shallow, `unshallow_repository` aborts retry when a sibling unshallows concurrently, `should_retry` callback returning False aborts the loop, and `_call_git` forces `LC_ALL=C`/`LANG=C`.
- `TestUpdatePrMergeBase` — unit tests for `SessionManager._update_pr_merge_base`: skips when SHA already set, skips when inputs are missing, sets the tag when both SHAs are present, skips when merge-base returns empty, and three wiring tests verifying it is called from `upload_git_data()` in shallow, non-shallow, and "all commits already known" scenarios.
- Updated `TestGitUnshallow` assertions to reflect that `_call_git_with_lock_retry` now calls `_call_git(args, input_string)` with two positional arguments (the old `[([cmd], _)]` destructuring assumed a single positional arg) and to patch `is_shallow_repository` for the new entry guard.
No regression tests (real shallow clone + full plugin run) were added; that would require a more involved fixture setup.
## Risks
Low. The changes are confined to the pytest plugin internals and only affect CI Visibility data collection, not any tracer hot paths.
- The retry logic only activates when a specific lock-error string is matched; all other errors fall through immediately as before.
- The C locale override only affects the subprocess environment for git commands; it does not change the locale for the rest of the process.
- `PULL_REQUEST_BASE_BRANCH_SHA` was already an optional tag — if `merge-base` fails it is simply absent, same as before.
- Removing `get_pr_base_commit_sha` is safe; grep confirms it had no callers outside its own definition.
Co-authored-by: federico.mon <federico.mon@datadoghq.com>1 parent b26f246 commit e886904
9 files changed
Lines changed: 492 additions & 117 deletions
File tree
- ddtrace/testing/internal
- releasenotes/notes
- tests/testing
- internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | 129 | | |
142 | 130 | | |
143 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| |||
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
123 | 135 | | |
124 | 136 | | |
125 | 137 | | |
| |||
129 | 141 | | |
130 | 142 | | |
131 | 143 | | |
| 144 | + | |
132 | 145 | | |
133 | 146 | | |
134 | 147 | | |
| |||
150 | 163 | | |
151 | 164 | | |
152 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
153 | 205 | | |
154 | 206 | | |
155 | 207 | | |
| |||
232 | 284 | | |
233 | 285 | | |
234 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
235 | 293 | | |
236 | 294 | | |
237 | 295 | | |
| |||
245 | 303 | | |
246 | 304 | | |
247 | 305 | | |
248 | | - | |
| 306 | + | |
249 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
250 | 313 | | |
251 | 314 | | |
252 | 315 | | |
| |||
294 | 357 | | |
295 | 358 | | |
296 | 359 | | |
297 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
298 | 365 | | |
299 | 366 | | |
300 | 367 | | |
| |||
324 | 391 | | |
325 | 392 | | |
326 | 393 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | 394 | | |
343 | 395 | | |
344 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
414 | 428 | | |
415 | 429 | | |
416 | 430 | | |
| |||
438 | 452 | | |
439 | 453 | | |
440 | 454 | | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | 455 | | |
446 | 456 | | |
447 | 457 | | |
448 | 458 | | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
459 | 470 | | |
460 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
461 | 483 | | |
462 | 484 | | |
463 | 485 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 2 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 166 | + | |
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | | - | |
391 | | - | |
| 390 | + | |
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
395 | 394 | | |
396 | 395 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | 396 | | |
457 | 397 | | |
458 | 398 | | |
| |||
0 commit comments