Skip to content

fix(adb): immune to adb-version conflicts + live-bound port detection#16

Merged
Jordan231111 merged 2 commits into
mainfrom
fix/adb-version-conflict-port-detection
Jun 2, 2026
Merged

fix(adb): immune to adb-version conflicts + live-bound port detection#16
Jordan231111 merged 2 commits into
mainfrom
fix/adb-version-conflict-port-detection

Conversation

@Jordan231111

Copy link
Copy Markdown
Owner

The report

A user hit instance '<name>' did not boot / become adb-reachable within 300 s even though the instance was fully booted (Home visible, Magisk installed). The instance was never the problem.

Root cause (reproduced on this machine)

The host had a system adb of a different version — Android SDK platform-tools v1.0.41 at …\Android\Sdk\platform-tools\adb.exe — alongside BlueStacks' bundled HD-Adb v1.0.36. When both touch the default adb server port 5037, they kill each other:

adb server version (41) doesn't match this client (36); killing...
error: device '127.0.0.1:5645' not found

So every getprop sys.boot_completed the tool issued failed, and Boot-And-Wait timed out at the throw.

The fix (host-side adb plumbing only)

  • Version-conflict immunity — pin HD-Adb to its own private server port ANDROID_ADB_SERVER_PORT=15037, and only ever use HD-Adb.exe (Resolve-HdAdb, never a system adb.exe). A foreign-version adb on 5037 can no longer touch our server. (HD-Adb v1.0.36 honours the env var — verified.)
  • Port detection hardenedGet-AdbPortCandidates now also consults the actually-bound listening port (Get-NetTCPConnection, band 5550-5900), merged after the bluestacks.conf status.adb_port/adb_port values (which stay authoritative). Rescues the boot wait when the conf is stale.
  • Mirror of the isolation in the engine's Connect-WaitBoot.
  • No change to the rooting pipeline, the embedded Magisk APK, or any on-disk format.

Validation (live, on Tiramisu64_9)

Test Result
Port detection, 20 runs cands=[5645,5555] identical all 20×, 0 missed the real port
Isolated (15037) + v41 server on 5037, 30× getprop OK=30, FAIL=0
Control (shared 5037, v36+v41), 12× getprop OK=0, FAIL=12 — reproduces the exact reporter error
Full Boot-And-Wait with v41 squatting 5037 PASS — booted, boot_completed=1, Is-BlueStacks=True

Also note: conf status.adb_port=5646 was stale while the instance was really on 5645 — the live scan found 5645 independently (the second value of the port-detection hardening).

Tests

  • tests/Run-Resolve-Tests.ps1: deterministic probe seam + 3 new conf+live merge/dedup cases → 25/25
  • tests/Run-Tests.ps128/28
  • tests/Check-Embedded-Sync.ps1 → engine + orchestrator + APK in sync (re-embedded blueStackRoot.cmd)

Boot-And-Wait was throwing "instance '<x>' did not boot / become
adb-reachable within 300 s" on hosts that ALSO have a different-version
system adb (Android SDK platform-tools v1.0.41) alongside BlueStacks'
HD-Adb v1.0.36. The two kill each other's adb server on the shared
default port 5037 ("server version doesn't match this client; killing"),
so getprop sys.boot_completed fails forever even though the instance
booted fine. Nothing about the instance is wrong.

- Pin HD-Adb to its OWN server port (ANDROID_ADB_SERVER_PORT=15037) and
  only ever use HD-Adb.exe (Resolve-HdAdb; never a system adb.exe).
- Merge the live-bound listening port (Get-NetTCPConnection, band
  5550-5900) into Get-AdbPortCandidates, AFTER the conf ports, to rescue
  a stale status.adb_port. Deterministic test seam for the live scan.
- Mirror the server isolation in the engine's Connect-WaitBoot.
- Run-Resolve-Tests: + probe seam and 3 merge/dedup cases (now 25);
  re-embedded into blueStackRoot.cmd; Check-Embedded-Sync + Run-Tests (28) pass.

Proven live with a v41 server on 5037: isolated getprop 30/30 OK, shared-port
control 0/12 (exact reporter error), port detection 20/20 stable, full
Boot-And-Wait end-to-end PASS.
…E->v11

Addresses "what if 15037 is already in use before my session":
- Resolve-AdbServerPort probes 15037..15057 and uses the first FREE port
  (reusing our own HD-Adb server if already up), so a non-adb app or a
  foreign-version adb already on 15037 is skipped, never fought. Explicit
  ANDROID_ADB_SERVER_PORT still wins. Mirrored in bsr_engine.ps1.
- Release our private adb server on exit (kill-server in a finally), so
  nothing of ours lingers on the port after the tool finishes.
- Run-Resolve-Tests: +6 free-port cases (now 31). Re-embedded; suites green.
- README: download link v9 -> v11; BlueStacks version 5.22.169 -> 5.22.210
  (the version we ran the boot/adb path on this session).

Verified live (real, non-stubbed probe): non-adb listener on 15037 -> tool
picks 15038; our own HD-Adb server on 15037 -> reused.
@Jordan231111 Jordan231111 merged commit d601a26 into main Jun 2, 2026
1 check passed
@Jordan231111 Jordan231111 deleted the fix/adb-version-conflict-port-detection branch June 2, 2026 22:43
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.

1 participant