Fix #306: end the stream when the console suspends - #318
Conversation
|
Hardware result, on a V1 console with Atmosphere, running in title takeover mode ( The hang is gone. Sleep during an active stream, then wake, previously gave a dead screen needing a 15 second power hold and a fresh payload injection. With this change the console wakes, the display comes back after a brief white flash while the display stack reinitialises, and the app stays responsive and exits cleanly. The overlay confirmed the path runs, in order: Also checked the case this could plausibly have regressed: pressing HOME mid stream, waiting, and returning. The stream stays up and resumes, so the behaviour One thing this does not fix, which was previously invisible because the console bricked first: after a real sleep the stream does not recover. Wifi is off while asleep, so the connection dies, and That looks like a separate issue in the connection lifecycle rather than something to fold in here, so I have left this PR scoped to the hang. I am instrumenting a build to find out whether |
|
Correction to my previous comment, plus the direct evidence for the root cause. I was wrong that the stream does not recover. It does. With a file log attached, a real sleep and wake gives: The reconnect in The evidence for the stale mapping. The same log confirms the decoder surfaces really are reallocated across a sleep, which is what makes the invalidation in this PR load bearing rather than merely harmless. nvmap handles cached by On resume: and the handles the renderer then maps after reconnecting: A completely disjoint set. Every mapping cached before the sleep was pointing at decoder memory that no longer existed in that form. Without the invalidation, The instrumentation used to produce this is a local diagnostic build, not part of this PR. |
|
What happens if you remove |
|
I tested it out. I built three versions: master with that line deleted, master untouched as a control, and this PR's branch unmodified. I used the same commit for the first two, so the only difference is just that one line. With the line deleted, sleep and resume still crashes. I got a solid orange screen, the console hung, and I had to hold down power to get out of it. Pressing Home mid-stream also kills the stream, and doing it a second time panicked Atmosphere with With the untouched master on the same commit: sleep and resume drops the stream, but the app stays up and relaunches fine, and pressing Home works 3/3 time. This PR's branch survives sleep and resume 3/3 with the controls still working afterwards. So it doesn't fix the crash, and it basically turns a recoverable stream drop into a hung console. One caveat: stock master degraded gracefully for me rather than hard-crashing the way #306 describes. So, this is really just measuring the effect of removing the call, not a reproduction of the original report. Also, the call isn't even in this repo. It's in the borealis submodule at |
|
Why not pause the stream and return to the games menu upon console sleep? This should avoid all "stream surviving sleep mode" issues, and is consistent with behavior on Android (though a bit less convenient than fully surviving sleep, but even then it's a "good enough" solution even if a better fix gets added in the future). |
Moonlight on Android ends the session when the app stops: Game.onStop() calls stopConnection() then finish(), so sleeping the phone mid stream drops you back to the host list. This does the same on Switch, where losing applet focus means the console sleeping or the HOME menu taking over. On focus loss it drops input and calls the existing terminate(false), so the stream ends and the view falls back to the host list. terminateApp is false, so only the stream stops; whatever is running on the host keeps running and can be resumed by reconnecting. Issue XITRIX#306 is a hung console after waking, and it lives in the window where the OS tears the graphics and network services down underneath a process that keeps running. Ending the stream removes the state rather than trying to repair it: there is nothing stale left to get wrong. Tested on hardware, three sleep cycles plus HOME: the stream ends, the host list appears, reconnecting works, no hang. Co-Authored-By: Claude <noreply@anthropic.com>
6f5fa71 to
6bd4dfe
Compare
|
Swapped this PR over to your suggestion. I built both and tested them on hardware first, three sleeps each plus home. Parity version ends the stream, lands on the host list, reconnects fine. The old approach kept the stream alive with controls working. Neither hangs, so reliability was a wash and it came down to which is less to go wrong later. This one reuses the existing Old approach is on my fork as |
This comment was marked as outdated.
This comment was marked as outdated.
Tried copying the file over the installed filename. Now it sometimes exits properly and sometimes crashes upon wake. I've managed to reproduce the crash via home screen, which should be easier to debug than sleep (since the latter disconnects gdb). |
The bug is that you call If I breakpoint It appears the change made is wildly concurrency-unsafe. Out of curiosity can you push your old code to a different branch for me to test? |
Size: XS
Why
#306 is a hung console after waking from sleep mid stream. Orange screen, unresponsive, hard power off to recover.
The hang lives in the window where the OS tears the graphics and network services down underneath a process that keeps running. This ends the stream at that point instead of trying to carry decoder and GPU state through it, so there is no stale state left to get wrong.
This matches Moonlight on Android, where
Game.onStop()callsstopConnection()thenfinish(): sleeping the phone mid stream ends the session and returns you to the host list. Suggested in review by @nyanpasu64, and after building and testing both approaches on hardware I agree it is the better one to ship.What changed
On losing applet focus, drop input and call the existing
terminate(false).terminateAppis false, so only the stream ends. Whatever is running on the host keeps running and can be resumed by reconnecting.Acceptance criteria
Test plan
Tested on hardware, Switch on Atmosphere, streaming a game from a PC:
I also built and tested the alternative, which keeps the session alive across the suspend and repairs the GPU frame mappings on the first resumed frame. That also survived three sleeps with no hang, so both are reliable. It is on my fork as
archive/306-renderer-invalidationif it is ever wanted.Out of scope