Skip to content

A reclaim's Android snapshot load can hang without limit and hold the device #1047

Closed

Description

@Nabil372

What happened

An Android emulator's lease ended and Simlock reclaimed it with standard clean, which loads the clean-baseline snapshot with adb -s <serial> emu avd snapshot load simlock_clean_baseline (reclaim in src/drivers/android/index.ts, line 1126 on main at 7ac7f18). That command never returned: the reclaim sat for 18 minutes before we stopped it, the device stayed in reclaiming, and with android.maxRunning at 1 no other Android lease could be granted meanwhile. The load runs through #runOrThrow without a timeoutMs, and the process runner sets none by default, so nothing ends it.

What you expected

A snapshot load that does not finish within a bounded time (a minute, say) is given up, the emulator is shut down, and the reclaim falls back to the existing shutdown-and-wipe path, so the slot comes back.

How to reproduce

It happened once, in our first half-hour of running Android leases as reusable; we have no reliable trigger. The path, with a reusable Android device:

  1. simlock daemon start (config: lease.identity.android left at reusable, capacity.config.limits.android.maxRunning: 1)
  2. simlock lease --platform android and release it (the first boot captures the clean baseline)
  3. Lease and release again (ours hung on a busy machine, load average well above its core count; we do not know that load is the cause)
  4. When the snapshot load stalls, the reclaim never ends and every later Android lease waits.

Environment

Simlock 0.3.0 at commit 6316e10 (the Android driver is unchanged on main at 7ac7f18), Android only. macOS 27.0.1 on an M5 Max (128 GB), Xcode 27.1, Android emulator 37.2.12, platform-tools 37.0.1, cmdline-tools 22.0, image system-images;android-37.0;google_apis;arm64-v8a, Simlock's default Pixel 9 profile. simlock doctor output was not captured at the time.

Logs and evidence

No daemon log of the hang was kept. The device stayed reclaiming for 18 minutes; adb emu avd snapshot load was still running when we stopped it. We worked around it by setting lease.identity.android to fresh, which skips the snapshot load. We have a tested change that gives the load a 60 s deadline (on the driver clock) and then kills the emulator and wipes; happy to open it as a PR if you want it.

Activity

  1. added
    bug:new
    on Oct 29, 2026
  2. self-assigned this
    on Oct 31, 2026
  3. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Reproduction

    Defect, confirmed as reported. Branch bug/1047-repro, src/drivers/android/index.test.ts: "ends a standard reclaim whose clean-baseline load never answers: the load is stopped, the emulator shut down, and the next boot wipes". The load hangs; the driver's clock moves ten minutes.

    pnpm exec vitest run --project unit src/drivers/android/index.test.ts -t "never answers"
    
    AssertionError: expected 'still running' to deeply equal { state: 'shutdown', strategy: 'wipe' }
     ❯ src/drivers/android/index.test.ts:854
    

    It also asserts the hung adb child ends, emu kill is sent, and the next makeReady uses -wipe-data.

    Root cause

    src/drivers/android/index.ts:1141 (on ce8fea8) runs emu avd snapshot load through #runOrThrow with no timeoutMs. NodeProcessRunner.run sets no timer when none is given (src/ports/process-runner.ts:203). The wait has no bound (architecture rule 11) and the device lock is held through it. The existing fallback at line 1150 (shut down, wipe) runs only once the load returns. The symptom shows up in core as a device stuck in reclaiming that holds maxRunning.

    Simplest fix

    Spawn the load and wait for it with the existing #waitForExit(handle, SNAPSHOT_LOAD_TIMEOUT_MS) on the driver clock (60 s, as the reporter proposes). On timeout, kill("SIGKILL") the child and take the same shutdown-and-wipe branch as a failed load. Also treat a non-zero exit as a failed load. A scratch version passed the whole file.

    Alternatives rejected

    • timeoutMs on #runOrThrow: the timer runs on real time, outside the driver clock, so the test cannot see it, and the throw skips the wipe fallback.
    • Making fresh the default Android identity: hides the hang without bounding it.

    Risk

    Side findings

    Written by an agent.

  4. removed their assignment
    on Oct 31, 2026
  5. added
    bug:ready
    and removed
    bug:new
    on Oct 31, 2026
  6. self-assigned this
    on Oct 31, 2026
  7. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Decision

    The triage's Simplest fix says a non-zero exit of emu avd snapshot load counts as a failed load and takes the shutdown-and-wipe path. No test pinned that line.

    • Decision: a non-zero exit of the clean-baseline load takes the same shutdown-and-wipe path as a load that times out (decided in delivery, pending the maintainer).
    • Tests: the reclaim test for the hung load gets a second case, a load that exits non-zero, with the same assertions ({ state: "shutdown", strategy: "wipe" }, emu kill sent, the next makeReady uses -wipe-data).

    Written by an agent.

  8. added a commit that references this issue on Oct 31, 2026
    75ca78c
  9. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Maintainer confirmed the decision above: a clean-baseline load that exits non-zero takes the shutdown-and-wipe path, the same as a load that times out. Kept as shipped in #1149.

    Written by an agent.

  10. V3RON commented on Nov 2, 2026

    @V3RON
    Contributor

    Follow-up: the Android reset this bug hit is replaced in #327 (Named baselines, ADR 0061). Every emulator becomes a copy of a source, booted from the source's snapshot at launch and destroyed after its lease, so no reclaim loads a snapshot into a running emulator any more (task #1205).

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions