Skip to content

fix: reject resume requests for stale sessions - #185

Open
brongan wants to merge 1 commit into
hgaiser:mainfrom
brongan:fix/reject-stale-resume
Open

fix: reject resume requests for stale sessions#185
brongan wants to merge 1 commit into
hgaiser:mainfrom
brongan:fix/reject-stale-resume

Conversation

@brongan

@brongan brongan commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Reject resume key updates when any of the following is true:

  • Shutdown has started.
  • The existing session is not Active.
  • An Active session has no key sender.

This is a narrow follow-up to #103. That PR added support for reconnecting to an active stream, but /resume currently treats any existing session object as resumable. The shutdown signal can fire before the watchdog clears that object, leaving a short window where Moonshine acknowledges a resume for a stream that can no longer produce frames.

Resume decision

Before this change, any existing session returned status 200. A missing key sender only logged a warning.

flowchart TD
    A["Receive /resume with new keys"] --> B{"Shutdown started?"}

    B -- Yes --> X["Return status code 400"]
    B -- No --> C{"Session is Active?"}

    C -- No --> X
    C -- Yes --> D{"Key sender exists?"}

    D -- No --> X
    D -- Yes --> E["Replace session keys"]
    E --> Y["Return status code 200"]
Loading

The original failure was observed during a Moonlight reconnect: Moonshine logged ControlStreamStopped, accepted /resume with status 200 during teardown, and then produced no video before Moonlight's first-frame timeout.

@brongan
brongan force-pushed the fix/reject-stale-resume branch 3 times, most recently from e334d3a to dcad9a8 Compare August 27, 2026 16:59
The /resume handler currently returns success whenever a session object exists, even after shutdown begins or before streaming is active. It also returns success when the session key sender is missing. Moonlight then waits for a reconnect that cannot produce frames.

Reject resume key updates when any of the following is true:

- shutdown has started
- the existing session is not Active
- an Active session has no key sender
@brongan
brongan force-pushed the fix/reject-stale-resume branch from dcad9a8 to e765765 Compare August 27, 2026 17:02
@brongan
brongan marked this pull request as ready for review August 27, 2026 17:08
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