Skip to content

feat(sessions): stop paused sessions and empty lobbies after an opt-in timeout - #592

Open
andrewdunndev wants to merge 2 commits into
games-on-whales:betafrom
andrewdunndev:feat/paused-session-timeout-v2
Open

andrewdunndev wants to merge 2 commits into
games-on-whales:betafrom
andrewdunndev:feat/paused-session-timeout-v2

Conversation

@andrewdunndev

Copy link
Copy Markdown
Contributor

Refiled from #581, which I closed unreviewed only because of the three-open-PR limit. The branch applies cleanly to current beta (ac2461f); the body is the same apart from small wording fixes.

Problem

A Moonlight client that vanishes without a clean quit (a device that sleeps, a dropped link) ends in an ENet disconnect.

  • Wolf turns that disconnect into PauseStreamEvent (control/control.cpp:180-185, :222-224), which stops the pipelines but not the session.
  • The session and its app container then run until someone stops them by hand.
  • A lobby created with stop_when_everyone_leaves false does the same once its last session has left (sessions/lobbies.cpp:61-64).

I found no peer timeout or idle path in src/.

Change

Two env vars, both default 0 (off). Unset or 0 creates no handler, atom or thread.

WOLF_PAUSED_SESSION_TIMEOUT_MS stops a session and its app container once it has stayed paused that long.

  • A Pause records an epoch and arms one deferred check. Resume or Stop clears it.
  • The check fires StopStreamEvent only if its epoch is still current, so a Resume after an earlier Pause is never undone.
  • A Pause for a session that is no longer running (the client's disconnect after a Stop) arms nothing.
  • A second Pause while armed is ignored.

WOLF_EMPTY_LOBBY_TIMEOUT_MS fires StopLobbyEvent once a lobby has had no joined session for that long after a leave.

  • The latest leave wins and emptiness is checked at expiry, so a rejoin keeps the lobby.
  • It overrides an explicit persistent lobby, hence opt-in.
  • It is the second commit and can be dropped alone.

Both:

  • Invalid or negative values warn and fall back to 0, as WOLF_WAYLAND_SOCKET_WAIT_TIMEOUT_MS does.
  • Both have configuration.adoc rows.
  • The timer is a detached sleeping thread, the idiom the neighbouring handlers use.

Limits:

  • A Pause arriving after a newer Resume is not defended (it already ends the live pipelines today).
  • The API pause endpoint also arms the timer.
  • Each Pause and each lobby leave holds one sleeping thread until expiry.

Tests

tests/testSessions.cpp, tag [Sessions], no GPU, Docker or peer. 3 test cases; 390 lines added, 232 of them tests.

  • Env parsing: unset, 1500, -1, garbage.
  • Paused sessions, 7 sections: Pause then Stop; Resume cancels; Pause again after a Resume restarts the timeout; Pause twice stops once; Stop cancels the pending Stop; Pause after Stop arms nothing; zero arms nothing.
  • Empty lobbies, 4 sections: Leave then StopLobby; rejoin keeps the lobby; leave again after a join restarts the timeout; zero arms nothing.

Rebuilt on beta ac2461f with both commits applied and run with Wolf's Catch2 suite: 43 of 43 test cases pass (1143 assertions), and clang-format 18 is clean. The existing "Lobbies APIs" case is excluded because my runner has no Wayland compositor (it fails the same way without this series).

Checked once that the tests catch a regression: with Resume changed so it no longer cancels, exactly the two Resume sections failed ("Resume before the timeout cancels the Stop", "Pausing again after a Resume restarts the timeout"). "Lobbies APIs" also failed, for the compositor reason above.

Real hardware

Two hosts, one AMD host and one NVIDIA host, each as server with Moonlight on the other.

  • Wolf built from beta source 35c7105 with this series, running Wolf UI.
  • The client was frozen with kill -STOP, so there was no clean disconnect.
  • Wolf logs the Pause about 6 s after the freeze (ping timeout).
server setting freeze to Stop session and app container after 4 min
AMD unset none still up
AMD WOLF_PAUSED_SESSION_TIMEOUT_MS=60000 66 s gone
NVIDIA unset none still up
NVIDIA WOLF_PAUSED_SESSION_TIMEOUT_MS=60000 66 s gone

On stock stable the frozen session and its container were still up after 10 min.

Empty lobby, AMD host: a persistent Steam lobby joined by a Moonlight session, then left through the API.

  • With WOLF_EMPTY_LOBBY_TIMEOUT_MS=60000, Wolf stopped it 60 s after the leave and removed the runner container.
  • Unset, the lobby was still up after 150 s.

Related

We have a small test bench (one AMD host with a discrete and an integrated GPU, one NVIDIA host, scripted Moonlight clients) and are glad to run A/B tests or take on side quests the community would find useful. The main limit is GPU age: our GPUs are a generation or two old.

A Moonlight client that disconnects without quitting the app, such as a
device going to sleep or a dropped link, leaves its session paused.
Wolf keeps that session and its app container until someone stops them
by hand.

WOLF_PAUSED_SESSION_TIMEOUT_MS (default 0, off) stops a session once it
has stayed paused for that many milliseconds. A Pause records an epoch
for the session and arms one deferred check; Resume or Stop clears it.
The check fires StopStreamEvent only if the epoch still matches, so a
resumed session is never stopped by an earlier Pause. A Pause for a
session that is no longer running, such as the client disconnecting
after a Stop, arms nothing.
A lobby created with stop_when_everyone_leaves set to false keeps its
app container running after the last session leaves, including when
that session was only paused by a sleeping client.

WOLF_EMPTY_LOBBY_TIMEOUT_MS (default 0, off) fires StopLobbyEvent once a
lobby has stayed empty for that many milliseconds after a session left
it. Each leave records a new epoch, so only the check armed by the
latest leave can stop the lobby, and only if it is still empty.

This branch has not been deployed

No deployments
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