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
This commit is contained in:
Kurt Himebauch authored and maxjivi05 committed 2026-11-03 13:25:08 -05:00
1 parent 77a332e615
commit dcd955e175
1 file changed
+24 -13
@@ -387,9 +387,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)
@@ -400,7 +401,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()
@@ -456,7 +456,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
}
@@ -483,8 +483,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
}
}
@@ -504,7 +504,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")
@@ -609,7 +609,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)
@@ -700,7 +700,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) {
@@ -722,8 +722,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) {
@@ -1879,11 +1879,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))