mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-19 16:01:57 +09:00
[MG_Remote, MG_Test] (P12 review): a lost server window is answered before every ring record, and a stopping in-process server leaves a streaming client's queue unapplied
- Major: the window-lost release was picked up only between drain batches (PumpControlRequest), and a client streaming frames keeps the command ring from emptying for seconds - surfaceDestroyed waited out its 3 s bound on the UI thread, answered TimedOut, and the session kept presenting into the destroyed window. DrainRing now checks the request after its latch check, before every pop. ServerLoopLatchTest.ALostServerWindowIsReleasedMidBatchWhileTheClientStreams streams a 4 s batch under Detach.
- Stop while streaming: mobilegl_server_stop_inprocess ended the session through loop.Stop(), whose batch and final drain of a ring the client keeps refilling could outlast the bounded join (Fatal{ApplyThreadJoinTimeout} aborts the display Activity's process). RunSession now calls ServerLoop::AbandonQueuedRecords() first when the server is stopping: the drain stops after the record in hand and the exit path declines the rest, as a ReverseChannelForfeit does. ServerLoopTest.StoppingTheServerUnderAStreamingClientLeavesTheQueueAndJoinsPromptly.
This commit is contained in:
@@ -210,6 +210,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
m_session = &session;
|
||||
m_stopRequested.store(false, std::memory_order_release);
|
||||
m_abandonQueue.store(false, std::memory_order_release);
|
||||
// PH-6 fix round: the session's copy of the request, for ReserveEventOrBlock's wait. Lowered
|
||||
// with the loop's own, so a loop restarted on the same session does not forfeit at once.
|
||||
session.ClearApplyStopRequest();
|
||||
@@ -506,13 +507,22 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// a peer that keeps publishing could keep this final drain going as long as it liked,
|
||||
// which is exactly the unbounded hold the forfeit exists to end. The queue is left
|
||||
// unapplied; the rings die with the session.
|
||||
//
|
||||
// AND AFTER AbandonQueuedRecords (P12 review fix), for the forfeit's reason: the server is
|
||||
// stopping under a client that may still be streaming, and draining what it keeps queuing
|
||||
// is the unbounded hold Stop()'s bounded join turns into an abort.
|
||||
const Bool forfeited = session.ReverseChannelForfeited();
|
||||
const Bool abandoned = m_abandonQueue.load(std::memory_order_acquire);
|
||||
PumpControlRequest();
|
||||
if (forfeited) {
|
||||
MGLOG_E("MG_Remote server: mgl-srv-apply stops on ReverseChannelForfeit - %llu reverse-channel "
|
||||
"event(s) dropped, applied seq %llu; the records still queued are not applied",
|
||||
static_cast<unsigned long long>(session.ForfeitDrops()),
|
||||
static_cast<unsigned long long>(session.Consumer().AppliedSeq()));
|
||||
} else if (abandoned) {
|
||||
MGLOG_W("MG_Remote server: mgl-srv-apply stops because the server is stopping - applied seq %llu; "
|
||||
"the records still queued are not applied",
|
||||
static_cast<unsigned long long>(session.Consumer().AppliedSeq()));
|
||||
} else {
|
||||
DrainRing();
|
||||
}
|
||||
@@ -712,12 +722,25 @@ namespace MobileGL::MG_Remote::Server {
|
||||
//
|
||||
// The idle poll's cost is unchanged: this load replaces the function-top check the first
|
||||
// version made, and the empty-ring answer is still it plus Pop's cmdHead load.
|
||||
//
|
||||
// P12 (D6) REVIEW FIX: A LOST SERVER WINDOW IS ANSWERED BEFORE EVERY POP TOO, not only by
|
||||
// PumpControlRequest between batches. A batch ends when the ring is empty, and a client
|
||||
// streaming frames keeps it from emptying for seconds: surfaceDestroyed (ServerDisplay::
|
||||
// Detach) waited that long on the UI thread - past its 3 s bound, so it gave up and the
|
||||
// session went on presenting into the destroyed window. Checked AFTER the latch check (the
|
||||
// MECHANICS row in ph_latch_sites.py pins that one as the loop's first statement); the
|
||||
// release latches ServerWindowLost, so `continue` takes the latch check's way out. One more
|
||||
// acquire load per pop; the empty-ring answer pays it once.
|
||||
ServerSession& session = *m_session;
|
||||
Transport::SessionConsumer& consumer = session.Consumer();
|
||||
PipeApplier& applier = session.Applier();
|
||||
Uint64 applied = 0;
|
||||
for (;;) {
|
||||
if (SessionLatched()) break;
|
||||
if (m_windowLostRequested.load(std::memory_order_acquire)) {
|
||||
ReleaseLostServerWindow();
|
||||
continue;
|
||||
}
|
||||
bool corrupt = false;
|
||||
const bool popped = consumer.ApplyOne(
|
||||
[this, &applier](const Transport::RingRecordView& record) {
|
||||
@@ -756,6 +779,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// loop-head check on the next iteration - ph_latch_sites.py's MECHANICS row pins that
|
||||
// check as the first statement of this loop.)
|
||||
if (session.ReverseChannelForfeited()) break;
|
||||
// P12 review fix: and the record in hand is the last one when the server is stopping
|
||||
// (AbandonQueuedRecords); same placement, same free empty-ring answer.
|
||||
if (m_abandonQueue.load(std::memory_order_acquire)) break;
|
||||
// TEST-ONLY scheduling point BETWEEN two records: after this record's own checks and
|
||||
// before the next pop's latch check. A control-thread latch stored here is seen by that
|
||||
// check (the first version let it through); one stored after the check and before the
|
||||
@@ -935,6 +961,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
m_exitCv.notify_all();
|
||||
}
|
||||
|
||||
void ServerLoop::AbandonQueuedRecords() { m_abandonQueue.store(true, std::memory_order_release); }
|
||||
|
||||
void ServerLoop::Stop() {
|
||||
if (!m_thread.joinable()) {
|
||||
// Never started, or already stopped. The backend may still exist - the hook builds
|
||||
|
||||
@@ -216,6 +216,15 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// Kill the doorbell, join the thread (bounded), then destroy the private backend object
|
||||
// ON THAT THREAD before it exits. Blocking by contract - see the header note.
|
||||
void Stop();
|
||||
// P12 review fix: THE NEXT Stop() LEAVES THE QUEUE UNAPPLIED. A Stop() normally lets the
|
||||
// apply thread finish its batch and drain what is still queued - the client's own drain
|
||||
// bounds that. A SERVER that is stopping (the in-process display server's
|
||||
// mobilegl_server_stop_inprocess) has a client that may still be streaming, and a batch plus
|
||||
// a final drain of a ring that client keeps refilling can outlast the bounded join
|
||||
// (Fatal{ApplyThreadJoinTimeout} aborts the display Activity's process). Called before Stop():
|
||||
// the drain stops after the record in hand and the exit path declines the rest, as a
|
||||
// ReverseChannelForfeit does. Reset by Start().
|
||||
void AbandonQueuedRecords();
|
||||
|
||||
Bool Running() const;
|
||||
|
||||
@@ -486,6 +495,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
ServerSession* m_session = nullptr;
|
||||
std::atomic<Bool> m_running{false};
|
||||
std::atomic<Bool> m_stopRequested{false};
|
||||
// P12 review fix: AbandonQueuedRecords() - read after every popped record and at the exit.
|
||||
std::atomic<Bool> m_abandonQueue{false};
|
||||
std::thread m_thread;
|
||||
// The apply thread's identity used to live here as an atomic<std::thread::id>. It is
|
||||
// Detail::g_applyThreadKey now - see the block at the top of this header for why the
|
||||
|
||||
@@ -437,6 +437,7 @@ int RunSession(std::unique_ptr<SocketTransport> control, std::vector<std::uint8_
|
||||
if (backendBuilt) {
|
||||
// Stop() joins a running apply thread (it destroys the backend on it), or - never
|
||||
// started - drops the backend here; either way the display lease goes with it.
|
||||
if (g_inProcessStop.load(std::memory_order_acquire)) loop.AbandonQueuedRecords();
|
||||
loop.Stop();
|
||||
session.SetBackend(nullptr);
|
||||
}
|
||||
@@ -723,6 +724,11 @@ int RunSession(std::unique_ptr<SocketTransport> control, std::vector<std::uint8_
|
||||
}
|
||||
}
|
||||
loop.SetControlProgressSink(nullptr, nullptr);
|
||||
// P12 review fix: A STOPPING SERVER DOES NOT DRAIN A STREAMING CLIENT. The session ends because
|
||||
// the display server is going away, not because its client finished - and a client still
|
||||
// streaming would keep the apply thread's final drain going past Stop()'s bounded join, whose
|
||||
// Fatal{ApplyThreadJoinTimeout} aborts this (the display Activity's) process.
|
||||
if (inProcess && g_inProcessStop.load(std::memory_order_acquire)) loop.AbandonQueuedRecords();
|
||||
loop.Stop();
|
||||
// Publish the final server window while log forwarding is still attached.
|
||||
MobileGL::MG_Util::PipeStats::Shutdown();
|
||||
|
||||
Reference in New Issue
Block a user