Commit 814f5a0
[FastDeploy] Retry first run-as query to absorb post-install data-dir race (XA0137) (#11809)
The Fast Deployment install-vs-`run-as` race (#7821) fires `XA0137` (`run-as: couldn't stat /data/user/0/<pkg>: No such file or directory`) on the **primary user (user 0)** ~daily in CI. The existing `EnsureUserIsRunning` mitigation (#11322) only covers secondary users and explicitly skips user 0 — and `am start-user -w 0` wouldn't help anyway, since user 0 is already running; the real issue is the brief window after `pm install` before `/data/user/0/<pkg>` is stat-able through `run-as`.
## Changes
`src/Xamarin.Android.Build.Debugging.Tasks/Tasks/FastDeploy.cs`:
- **`QueryInternalPathWithRetry`** — wraps the first `run-as <pkg> pwd` query in `CheckAppInstalledAndDebuggable` with a bounded poll (10 attempts × 500 ms) that retries while the result matches the transient race signature, before falling through to `RaiseRunAsError`/XA0137. Applies to **all** users, including user 0; no-op when the directory already exists.
- **`IsTransientRunAsStatRace`** — matches the `couldn't stat … No such file or directory` signature only, so genuine `run-as` failures (permission denied, not debuggable, corrupt install, etc.) still surface immediately.
```csharp
async Task<string> QueryInternalPathWithRetry ()
{
const int maxAttempts = 10;
var delay = TimeSpan.FromMilliseconds (500);
string result = await Device.RunAs (packageInfo, "pwd");
for (int attempt = 1; attempt < maxAttempts && IsTransientRunAsStatRace (result); attempt++) {
LogDiagnostic ($"run-as could not stat the data directory for {packageInfo.PackageName} yet (attempt {attempt}/{maxAttempts}); retrying in {delay.TotalMilliseconds:0} ms. Output: {result?.Trim ()}");
await Task.Delay (delay, CancellationToken);
result = await Device.RunAs (packageInfo, "pwd");
}
return result;
}
```
`EnsureUserIsRunning` is left intact; the retry sits after it, so secondary users retain both mitigations.
## Notes
No unit-test project exists for `Xamarin.Android.Build.Debugging.Tasks`; the path is exercised by the on-device `MSBuildDeviceIntegration` install tests where the race was observed.
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>1 parent 36df374 commit 814f5a0
3 files changed
Lines changed: 100 additions & 1 deletion
File tree
- src
- Xamarin.Android.Build.Debugging.Tasks
- Properties
- Tasks
- Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
Lines changed: 48 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| |||
395 | 395 | | |
396 | 396 | | |
397 | 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 | + | |
398 | 445 | | |
399 | 446 | | |
400 | 447 | | |
| |||
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
77 | 127 | | |
0 commit comments