[Sharding] Fix Android session reuse with dynamic driver ports#3307
Open
sdfgsdfgd wants to merge 1 commit into
Open
[Sharding] Fix Android session reuse with dynamic driver ports#3307sdfgsdfgd wants to merge 1 commit into
sdfgsdfgd wants to merge 1 commit into
Conversation
c144716 to
e7637a0
Compare
d25d7fc to
de84a26
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix Android persistent-session reuse when a later process reconnects to an existing driver session whose Android driver port was chosen dynamically.
This is a follow-through on the Android sharding/session thread, not a new sharding model.
Changes
driverHostPortinSessionStore.MaestroSessionManagerreconnects to an active session for the same device.launchApp()from lazily callingopen()when the current process is intentionally reusing an existing driver session.maestro start-sessionsupport so the persistent-session path from Add start session command to increase speed of tests #1902 is reachable and testable.--driver-host-portcorrectly throughstart-device.Context
Connection refusedsymptom.start-sessionand correctly identified that AndroidlaunchApp()could defeat session reuse by callingopen().A few historical details matter here.
Before #3138, session identity was too broad for sharded Android runs. A shard could observe another shard's Android heartbeat and incorrectly decide it did not need to open its own driver.
The old
launchApp()lazy-open fallback could sometimes mask that false reuse, but only iflaunchApp()was the first driver call. Calls likedeviceInfo()could still fail beforelaunchApp()had any chance to reopen the driver, which matches the failure shape in #1853.#3138 fixed the larger session identity problem by moving session tracking to
{platform, deviceId}and adding cross-process file locking. The remaining Android gap was port ownership: for sharded runs, the driver host port can be dynamic, so "there is an active session for this device" is still not enough. The reconnecting process also needs the driver port owned by that active session.Android
launchApp()The
launchApp()change follows directly from #1902:AndroidDriver.openis local to the current driver object, not proof that no driver session exists.In a reused persistent session,
open == falsecan simply mean this process did not start instrumentation itself. Callingopen()fromlaunchApp()in that state restarts instrumentation and defeatsstart-session.This PR removes that fallback and leaves the open/reuse decision in
MaestroSessionManager.Session Store
The heartbeat still records session liveness, but it now also carries the optional Android driver port:
Old timestamp-only heartbeat values remain supported. They parse as active sessions with no stored driver port.
This keeps existing session liveness behavior while making the reuse decision complete: a later process can skip startup and connect its gRPC channel to the same endpoint as the already-running Android driver.
Validation
git diff --check./gradlew :maestro-client:compileKotlin :maestro-cli:test --tests maestro.cli.session.SessionStoreTest :maestro-cli:installDistemulator-5554:start-sessionwith--driver-host-port 61234~/.maestro/sessionsrecordeddriverHostPort:61234maestro testprocess that selected another free port (51911)start-session