Skip to content

fix(adb): Force-stop the app before each launch and after a run timeout - #64

Merged
bitsandfoxes merged 7 commits into
mainfrom
fix/adb-hung-launch
Oct 29, 2026
Merged

bitsandfoxes merged 7 commits into
mainfrom
fix/adb-hung-launch

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AdbProvider now force-stops the package before it launches it, and again after a run that didn't exit within the run timeout.

Until now, a run that hung left its process alive, and the provider only printed a warning. The next am start -W then didn't start a new process: it brought the hung activity back to the front, so pidof returned the same PID, the run waited out the full timeout again, and logcat --pid returned next to nothing. One hung launch failed every launch after it. In sentry-unity's Android integration tests, 7 jobs in the last 30 days went this way (e.g. 118708786184: App PID: 4056 for all five launches, 0 of 81 tests passed, 25 of the job's 30 minutes spent waiting).

How it works now:

  • RunApplication runs am force-stop <package> before clearing logcat and launching, so every launch starts a fresh process. This matches what iOSSimulatorProvider (simctl terminate) and SauceLabsProvider (mobile: terminateApp) already do before a launch.
  • After a run timeout, it reads the run's logs first and then force-stops the package, so the hung process doesn't outlive the run.
  • A failing force-stop only logs a warning; the launch goes ahead as before.

I left out an early "the app logged nothing yet" timeout: the provider has no app-agnostic readiness signal (what an app logs first is up to the engine), and adding one means a new Invoke-DeviceApp parameter for every provider plus logcat polling in the monitor loop. Callers that know their app can detect a launch that never initialised from the returned output and relaunch it, which sentry-unity does in getsentry/sentry-unity#2901.

Tests: AdbRunApplication.Tests.ps1 covers the order of commands on a normal run and on a timeout, and that a failing force-stop doesn't block the launch, with InvokeCommand faked (no device needed).

Stacked on #63.

CI evidence: run 40185846696, with a throwaway commit (since dropped) that made the first launch wait for a debugger, so it never initialised. In all 4 Run Android jobs, the first launch (Message Capture) waited out the timeout, then logged ::warning::Android app never initialised, relaunching (1/1). The relaunch came up under a new PID (e.g. 121151142372: 4326 → 6421) and each job passed 77/77 (4 skipped).

🤖 Generated with Claude Code

BootSimulator cleared FreshlyBooted before simctl boot, so a second boot
of a simulator this provider just booted (Connect, then Start-Device)
hit the already-Booted early return with the flag lost, and the first
launch ran the simctl terminate the fresh-boot skip exists to avoid.
Clear it only once the boot command has run.
The test got there by having the fake boot throw 'Unable to boot device
in current state: Booted', but the real InvokeBuiltCommand throws an
exit-code message, so production reaches an already-booted simulator
through SelectAndConnect's booted branch. Connect by UUID to a simulator
the fake lists as Booted instead, so that branch is covered.
BootSimulator matched simctl's 'Unable to boot device in current state:
Booted' text, but InvokeBuiltCommand throws only 'Command (boot) failed
with exit code N', so a second boot of a simulator this provider booted
rethrew instead of keeping FreshlyBooted. Ask for the simulator state
when boot fails and rethrow the boot error unless it is Booted, and have
the test fake throw the exit-code message the real command throws.
Matches the helper name SauceLabsProvider uses for the same job (and the
'terminate' wording iOS Simulator uses), so searching for how providers
reset the app before a run finds Adb too. The 'force-stop' command key and
warning text stay, since they name the adb verb.
@bitsandfoxes
bitsandfoxes changed the base branch from feat/test-event-filter to main October 29, 2026 11:07
@bitsandfoxes
bitsandfoxes merged commit aeae6e1 into main Oct 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants