diff --git a/native/cluster-render/src/slots.cpp b/native/cluster-render/src/slots.cpp index 4e5e8d4f..6fbb00bd 100644 --- a/native/cluster-render/src/slots.cpp +++ b/native/cluster-render/src/slots.cpp @@ -1664,11 +1664,28 @@ void SlotManager::verify(int i, int64_t now_ms) t.recoveries == 1 ? " at once" : " on the ladder"); take_down(i, now_ms); /* From the second recovery on the publication itself may be what the renderer missed: unpublished, so the - * next acquire publishes it again (a fresh offer); then, now and again, the framework reconnected */ + * next acquire publishes it again (a fresh offer); then, now and again, the framework reconnected, unless + * another target's scene is subscribed: the session is served, only this target's renderer is absent */ if (t.recoveries >= 2) drop_scene(i); - if (t.recoveries % kReconnectAfter == 0) - reconnect(i, "no renderer subscription through " + std::to_string(t.recoveries) + " recoveries in a row", now_ms); + if (t.recoveries % kReconnectAfter == 0) { + const std::string why = + "no renderer subscription through " + std::to_string(t.recoveries) + " recoveries in a row"; + int other = -1; + auto o = subs_.begin(); + for (; o != subs_.end(); ++o) { + other = by_published(o->first); + if (!o->second.empty() && other >= 0 && other != i) + break; + } + if (o == subs_.end()) + reconnect(i, why, now_ms); + else + log_warn("target %s: %s; the RAMSES framework not reconnected: target %s's scene 0x%llx is subscribed by " + "renderer %s", + spec.name.c_str(), why.c_str(), specs_[other].name.c_str(), (unsigned long long)o->first, + o->second.begin()->first.c_str()); + } if (t.recoveries == 1) set(i, TargetState::Waiting, Holder::None, reason, now_ms, now_ms); else diff --git a/native/cluster-render/src/slots.h b/native/cluster-render/src/slots.h index 62373a4b..782203e2 100644 --- a/native/cluster-render/src/slots.h +++ b/native/cluster-render/src/slots.h @@ -167,8 +167,10 @@ * (or after the renderer unsubscribed) is released and asked for again, * at once the first time and on the ladder after that; from the second * in a row its scene is unpublished, and every kReconnectAfter-th the - * unit reconnects (on_renderer_stuck). Before any subscription has been - * seen nothing is verified. + * unit reconnects (on_renderer_stuck), unless another target's scene is + * subscribed: the renderer serves the session, only this target's renderer + * is absent, and a reconnect would drop every target's content. Before any + * subscription has been seen nothing is verified. * - Holds: a target that follows another (TargetSpec::follows) keeps its * slot from the stock HMI while that target is shown and one of its * take_over_contents is mapped in the slot (follow(), which keeps a @@ -539,8 +541,8 @@ class SlotManager { std::function budget_text; /* The unit reconnects its RAMSES framework: a participant session the display no longer serves (one it kept * over a restart of this side, or one whose fetches it stopped completing). Called at every kReconnectAfter-th - * recovery in a row of a target whose renderer never subscribes, or of a stalled fetch (above), at most once per - * kReconnectGapMs. Unset: the ladder only. */ + * recovery in a row of a target whose renderer never subscribes while no other target's scene is subscribed, + * or of a stalled fetch (above), at most once per kReconnectGapMs. Unset: the ladder only. */ std::function on_renderer_stuck; static constexpr int kReconnectAfter = 3; diff --git a/native/cluster-render/test/service_test.cpp b/native/cluster-render/test/service_test.cpp index 82fac2a2..46c8cdcc 100644 --- a/native/cluster-render/test/service_test.cpp +++ b/native/cluster-render/test/service_test.cpp @@ -1022,6 +1022,73 @@ static void hud_yield_choice() ok("and gives way", r.svc->slots().status(k).state == TargetState::Waiting); } +/* A target whose renderer never subscribes (a HUD the display does not draw) next to one whose scene is + * subscribed: the first is recovered on the ladder again and again, the framework never reconnected (that drops + * every target's content), the other never taken down. With no target subscribed the reconnect goes as before. */ +static void one_renderer_absent() +{ + Rig r; + const uint64_t kPanelScene = 0x010004f8, kHudScene = 0x01000400; + r.sc.targets[1].scene_id = kPanelScene; /* the panel on its own id, as cluster-render.conf ships it */ + TargetSpec h; + h.name = "hud"; h.slot = 0x323; h.scene_id = kHudScene; h.width = 800; h.height = 480; h.linger_ms = 3000; + r.sc.targets.push_back(h); + r.start(); + SlotManager &m = r.svc->slots(); + int stuck = 0; + m.on_renderer_stuck = [&stuck, &r](int64_t) { + stuck++; + r.port.watchdog(); /* as the display does: every content of the participant dropped */ + }; + cr::Client a("app", r.path); + Events ea; + ea.wire(a); + r.clients = {&a}; + r.pump(50); + const cr::EffectOptions white{"#version 100\nvoid main(){gl_FragColor=vec4(1.0);}", "", 0}; + cr::LayerOptions lo; + lo.target = "panel"; + lo.contend = true; + a.effect(lo, white); + lo.target = "hud"; + a.effect(lo, white); + r.pump(200); + const int panel = m.index("panel"), hud = m.index("hud"); + m.on_subscription(kPanelScene, true, false, "renderer-1", r.now); + r.pump(10); + ok("absent renderer: the panel shown and rendered, the hud shown", + m.status(panel).state == TargetState::Shown && m.status(panel).rendering == Rendering::Verified && + m.status(hud).state == TargetState::Shown); + + uint64_t seq = 0; + std::vector lines; + cld::log_lines_since(&seq, &lines); + int recoveries = 0, kept_on = 0, panel_lost = 0; + bool panel_shown = true; + for (int k = 0; k < 4000 && recoveries < 3 * SlotManager::kReconnectAfter; k++) { + r.pump(100, 10); + lines.clear(); + cld::log_lines_since(&seq, &lines); + for (const std::string &l : lines) { + recoveries += has(l, "target hud: the display reports scene 0x1000400 mapped but its renderer is not " + "subscribed"); + kept_on += has(l, "the RAMSES framework not reconnected: target panel's scene 0x10004f8 is subscribed " + "by renderer renderer-1"); + panel_lost += has(l, "INCIDENT target panel lost"); + } + panel_shown = panel_shown && m.status(panel).state == TargetState::Shown && r.port.row(0x203, kPanelScene); + } + ok("the hud never subscribed through 3 x kReconnectAfter recoveries: no framework reconnect, each skip logged", + recoveries == 3 * SlotManager::kReconnectAfter && stuck == 0 && kept_on == 3); + ok("the panel shown and rendered throughout, never lost", + panel_shown && panel_lost == 0 && m.status(panel).rendering == Rendering::Verified); + + m.on_renderer_gone("renderer-1", r.now); + for (int k = 0; k < 600 && !stuck; k++) + r.pump(100, 10); + ok("no target subscribed: a kReconnectAfter-th recovery in a row reconnects the framework", stuck == 1); +} + static void scene_files() { char tmpl[] = "/tmp/crs-service-scenes-XXXXXX"; @@ -1973,6 +2040,7 @@ int main() guide_hold(); guide_hold_choice(); hud_yield_choice(); + one_renderer_absent(); display_drops(); repeats(); framing();