From 0a0bbb68d1ad57b2db9b7809cb464494a1e26368 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:44:12 -0500 Subject: [PATCH] fix: a stale session's startup failure no longer stops the newer session (#1984) * fix: a stale session's startup failure no longer stops the newer session * fix: stale session failures and queued-launch cleanup are checked against the current session under the stop lock --- .../launcher/session/SessionService.kt | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 7e748b7f92..1997a55368 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -372,9 +372,10 @@ class SessionService : Service() { SessionState.steamUi = intent?.getStringExtra(EXTRA_STEAM_UI) SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL) com.droiddeck.launcher.stores.battlenet.BattleNetClient.clearRequests(LinuxRuntime.sessionRoot(this)) - synchronized(stopLock) { + val gen = synchronized(stopLock) { SessionState.steamClientArch = null SessionState.running = true + ++sessionGen } if (SessionState.stopRequested) { stopSession(0) @@ -385,7 +386,6 @@ class SessionService : Service() { SessionState.guestPid = -1 SessionEvents.transition(SessionPhase.STARTING_GUEST, "service.started", mapOf("mode" to SessionState.mode)) com.droiddeck.launcher.wayland.CompositorHost.newSession() - val gen = ++sessionGen SessionPrefs.backgroundAppLimit(this).takeIf { it != com.droiddeck.launcher.core.BackgroundAppLimit.OFF } ?.let { com.droiddeck.launcher.core.BackgroundAppLimit.applyAsync(this, it) } if (SessionPrefs.clearCachedApps(this)) clearCachedApps() @@ -441,7 +441,7 @@ class SessionService : Service() { LinuxRuntime.writeAccounts(this) } catch (e: Exception) { Log.e(TAG, "could not write the guest's passwd/group", e) - stopSession(-1) + stopSession(-1, gen) return } @@ -468,8 +468,8 @@ class SessionService : Service() { } else { val message = getString(R.string.session_proot_missing) Log.e(TAG, "$message (pack ready=$prootPack)") - SessionEvents.fail("PROOT_MISSING", message, -1) - stopSession(-1) + failSession(gen, "PROOT_MISSING", message, -1) + stopSession(-1, gen) return } } @@ -489,7 +489,7 @@ class SessionService : Service() { GameEnvironmentStore.publish(this) } catch (e: Exception) { Log.e(TAG, "could not publish the game environment", e) - stopSession(-1) + stopSession(-1, gen) return } val sessionLog = File(sessionDir, "session.log") @@ -587,7 +587,7 @@ class SessionService : Service() { val program = SessionState.program if (program.isNullOrEmpty()) { Log.e(TAG, "run mode without a program") - stopSession(65) + stopSession(65, gen) return } guest.add(program) @@ -682,7 +682,7 @@ class SessionService : Service() { } val program = programStatus(sessionRoot) Log.i(TAG, "session ended: $status" + if (program != null) " (program $program)" else "") - stopSession(program ?: status ?: -1) + stopSession(program ?: status ?: -1, gen) }, null, sessionLog.takeIf { "PROOT_PROFILE=1" in hostEnv.asArray() }) Log.i(TAG, "session pid $pid, log ${sessionLog.path}") if (gen != sessionGen || !SessionState.running) { @@ -704,8 +704,8 @@ class SessionService : Service() { SessionEvents.guestStarted(pid) } else { SessionEvents.record("guest.start_failed", mapOf("pid" to pid)) - SessionEvents.fail("GUEST_START_FAILED", "The guest process could not be started", pid) - stopSession(-1) + failSession(gen, "GUEST_START_FAILED", "The guest process could not be started", pid) + stopSession(-1, gen) return } if (gen == sessionGen && SessionState.running) { @@ -1866,11 +1866,22 @@ class SessionService : Service() { }, "tracer-priority").start() } - private fun stopSession(status: Int) { - cancelQueuedSteamGame() - gameExitWatchToken++ + private fun failSession(gen: Int, code: String, message: String, status: Int?) { + synchronized(stopLock) { + if (gen == sessionGen) SessionEvents.fail(code, message, status) + } + } + + private fun stopSession(status: Int, gen: Int? = null) { + if (gen != null && gen != sessionGen) { + Log.i(TAG, "ignoring a stop from session $gen; session $sessionGen is current") + return + } completeNativeSleep() val (ended, endedArch) = synchronized(stopLock) { + if (gen != null && gen != sessionGen) return + cancelQueuedSteamGame() + gameExitWatchToken++ if (!SessionState.running) return SessionEvents.record("guest.exited", mapOf("status" to status)) SessionEvents.transition(SessionPhase.STOPPING, "session.stopping", mapOf("status" to status))