A restarted daemon can hand one emulator's console port to another device
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- android, typescript
- Domain
- devtools
Research direction
Start in src/drivers/android/index.ts by tracing PortAllocator reservations, AndroidDriver startup, and the registry boundary around listManaged(). Then inspect the scripted ProcessRunner tests and DeviceRecord.address handling to define the restart → provision → boot regression case. Done means a registry-known shutdown device keeps its port, the regression test passes, and pnpm check is green.
Written by the indexing model from the issue text.
Description
Problem
Found while implementing #14, deliberately left out of that PR (#50) because it changes the boot path rather than the lease payload.
PortAllocator (src/drivers/android/index.ts) tracks reservations in an in-memory #reserved set, and picks a free port by unioning that set with the ports it can see in adb devices:
const unavailable = new Set([...this.#reserved, ...portsFromAdbDevices(result.stdout)]);
adb devices only lists live emulators. A device in shutdown is not live, and its port lives only in #reserved — which dies with the daemon process.
So, after a restart:
- Device A is
shutdown, withport: 5554persisted in itsdriverData. - The daemon restarts.
#reservedis empty. - Device B is provisioned.
adb devicesshows nothing on 5554, so B is allocated 5554 and boots on it. - Device A is asked for next.
#startEmulatorpasses-port 5554, which B holds.
-port pins the console port rather than falling back to a free one, so step 4 is a boot failure, not a silent mislanding. That failure mode is at least loud — but it strands a registered device that has nothing wrong with it, and the collision only surfaces at lease time, when an agent is waiting.
Why now
Not new, and not caused by #14 — but #14's address makes it easier to reason about, since a device's reachable address is now persisted and re-read on every makeReady.
Options
Not obviously one right answer, hence an issue rather than a patch:
- Seed reservations at startup.
AndroidDrivercould reserve the ports of every registry-known device when it starts, so a shutdown device's port is not handed out. Cleanest fix conceptually; needs the driver to learn the registry's device list at construction, which is a boundary question (listManaged()sees only live emulators, so it isn't enough on its own). - Verify the port before each boot. Re-check the reserved port at every genuine boot and move to a fresh one when it is taken. I drafted this while working on #50 and backed it out: it works, but it costs an
adb devicescall per boot and reads as a workaround for a reservation that should not have been lost. - Do nothing yet, but fail better. Detect the collision at boot and produce a clear driver error naming the device that holds the port, instead of an emulator startup failure.
Notes
- iOS is unaffected: a simctl UDID is assigned at creation and never reassigned.
- Whatever shape this takes,
DeviceRecord.addressmust end up truthful afterwards; the plumbing from #14 already commits whatever the driver reports at each readiness transition.
Acceptance criteria
- A device provisioned after a restart is never allocated a port that a registry-known shutdown device is holding.
- Regression test with a scripted
ProcessRunnercovering the restart → provision → boot sequence. -
pnpm checkgreen.
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 0
- Avg merge
- 22h 33m
- Merged PRs (30d)
- 60
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from callstackincubator/simlock
-
bug:ready
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
callstackincubator/simlock#79 · 4 comments ·
-
feature:spec
Difficulty 5/5 Over a week Newbie friendliness 28/100
callstackincubator/simlock#88 · 1 comment ·
-
task:draft
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
task:draft
Difficulty 5/5 Over a week Newbie friendliness 35/100
callstackincubator/simlock#77 · 1 comment ·
-
task:draft
Difficulty 5/5 Over a week Newbie friendliness 35/100
callstackincubator/simlock#76 · 1 comment ·
All issues in callstackincubator/simlock
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/claude-code#96687 ·
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
AOSSIE-Org/DebateAI#582 · 2 comments ·